Merge "Fix RVCVXCheck OpenCV load error and other improvements" into marshmallow-cts-dev am: 9d82a66415 am: f9002b2455 am: a3fb3f57e6 am: 8658d77f06 am: 0aa9cd5e6a
am: 45da519a60
* commit '45da519a602620436332ec7152c030d22db1eeb2':
Fix RVCVXCheck OpenCV load error and other improvements
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 320734c..25ca6dd 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -196,6 +196,7 @@
CtsProviderTestCases \
CtsRenderscriptTestCases \
CtsRenderscriptLegacyTestCases \
+ CtsRsBlasTestCases \
CtsRsCppTestCases \
CtsSaxTestCases \
CtsSecurityTestCases \
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
index 6b9316f..44e2e0f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
@@ -154,6 +154,7 @@
List<ResolveInfo> getResolveInfosForParent() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.addCategory(CATEGORY_MANUAL_TEST);
+ mainIntent.setPackage(mContext.getPackageName());
PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(mainIntent,
diff --git a/build/test_deqp_package.mk b/build/test_deqp_package.mk
index 650875c..570669d 100644
--- a/build/test_deqp_package.mk
+++ b/build/test_deqp_package.mk
@@ -26,16 +26,16 @@
$(cts_library_xmls) : $(CTS_TESTCASES_OUT)/%.xml: external/deqp/android/cts/master/%.xml $(CTS_EXPECTATIONS) $(CTS_UNSUPPORTED_ABIS) $(CTS_XML_GENERATOR)
$(hide) echo Generating test description $@
$(hide) mkdir -p $(CTS_TESTCASES_OUT)
-# Query build ABIs by routing a dummy test list through xml generator and parse result
- $(hide) $(eval supported_abi_attr := $(shell $(CTS_XML_GENERATOR) -t dummyTest \
- -n dummyName \
- -p invalid.dummy \
- -e $(CTS_EXPECTATIONS) \
- -b $(CTS_UNSUPPORTED_ABIS) \
- -a $(CTS_TARGET_ARCH) \
- < $(PRIVATE_DUMMY_CASELIST) \
- | grep --only-matching -e " abis=\"[^\"]*\""))
-# Patch xml caselist with supported abi
- $(hide) $(SED_EXTENDED) -e 's:^(\s*)<Test ((.[^/]|[^/])*)(/?)>$$:\1<Test \2 $(supported_abi_attr)\4>:' \
+
+# Query build ABIs by routing a dummy test list through xml generator and parse result. Use sed to insert the ABI string into the XML files.
+ $(hide) SUPPORTED_ABI_ATTR=`$(CTS_XML_GENERATOR) -t dummyTest \
+ -n dummyName \
+ -p invalid.dummy \
+ -e $(CTS_EXPECTATIONS) \
+ -b $(CTS_UNSUPPORTED_ABIS) \
+ -a $(CTS_TARGET_ARCH) \
+ < $(PRIVATE_DUMMY_CASELIST) \
+ | grep --only-matching -e " abis=\"[^\"]*\""` && \
+ $(SED_EXTENDED) -e "s:^(\s*)<Test ((.[^/]|[^/])*)(/?)>$$:\1<Test \2 $${SUPPORTED_ABI_ATTR}\4>:" \
< $< \
> $@
diff --git a/build/test_target_java_library.mk b/build/test_target_java_library.mk
index fe1000a..525abb5 100644
--- a/build/test_target_java_library.mk
+++ b/build/test_target_java_library.mk
@@ -50,4 +50,4 @@
-o $@
# Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_library_jar) $(cts_library_xml $(cts_module_test_config))
+$(my_register_name) : $(cts_library_jar) $(cts_library_xml) $(cts_module_test_config)
diff --git a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
index 14f215c..9d38a94 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
+++ b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
@@ -252,7 +252,7 @@
}
return null;
}
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
return pipe[1];
} else {
new AsyncTask<Void, Void, Void>() {
@@ -275,7 +275,7 @@
}
return null;
}
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
return pipe[0];
}
}
diff --git a/hostsidetests/security/Android.mk b/hostsidetests/security/Android.mk
index d9fbc65..ad708ca 100644
--- a/hostsidetests/security/Android.mk
+++ b/hostsidetests/security/Android.mk
@@ -31,13 +31,23 @@
selinux_general_seapp_contexts := $(call intermediates-dir-for,ETC,general_seapp_contexts)/general_seapp_contexts
-selinux_general_file_contexts := $(call intermediates-dir-for,ETC,general_file_contexts)/general_file_contexts
+selinux_general_seapp_neverallows := $(call intermediates-dir-for,ETC,general_seapp_neverallows)/general_seapp_neverallows
+
+selinux_general_file_contexts := $(call intermediates-dir-for,ETC,general_file_contexts.bin)/general_file_contexts.bin
selinux_general_property_contexts := $(call intermediates-dir-for,ETC,general_property_contexts)/general_property_contexts
selinux_general_service_contexts := $(call intermediates-dir-for,ETC,general_service_contexts)/general_service_contexts
-LOCAL_JAVA_RESOURCE_FILES := $(HOST_OUT_EXECUTABLES)/sepolicy-analyze $(HOST_OUT_EXECUTABLES)/checkseapp $(HOST_OUT_EXECUTABLES)/checkfc $(selinux_general_seapp_contexts) $(selinux_general_file_contexts) $(selinux_general_property_contexts) $(selinux_general_service_contexts)
+LOCAL_JAVA_RESOURCE_FILES := \
+ $(HOST_OUT_EXECUTABLES)/sepolicy-analyze \
+ $(HOST_OUT_EXECUTABLES)/checkseapp \
+ $(HOST_OUT_EXECUTABLES)/checkfc \
+ $(selinux_general_seapp_contexts) \
+ $(selinux_general_seapp_neverallows) \
+ $(selinux_general_file_contexts) \
+ $(selinux_general_property_contexts) \
+ $(selinux_general_service_contexts)
selinux_general_policy := $(call intermediates-dir-for,ETC,general_sepolicy.conf)/general_sepolicy.conf
diff --git a/hostsidetests/security/src/android/cts/security/SELinuxHostTest.java b/hostsidetests/security/src/android/cts/security/SELinuxHostTest.java
index abb1ac4..c80d676 100644
--- a/hostsidetests/security/src/android/cts/security/SELinuxHostTest.java
+++ b/hostsidetests/security/src/android/cts/security/SELinuxHostTest.java
@@ -66,6 +66,7 @@
private File deviceFcFile;
private File devicePcFile;
private File deviceSvcFile;
+ private File seappNeverAllowFile;
/**
* A reference to the device under test.
@@ -113,10 +114,10 @@
deviceSeappFile.deleteOnExit();
mDevice.pullFile("/seapp_contexts", deviceSeappFile);
- /* obtain file_contexts file from running device */
- deviceFcFile = File.createTempFile("file_contexts", ".tmp");
+ /* obtain file_contexts.bin file from running device */
+ deviceFcFile = File.createTempFile("file_contexts", ".bin");
deviceFcFile.deleteOnExit();
- mDevice.pullFile("/file_contexts", deviceFcFile);
+ mDevice.pullFile("/file_contexts.bin", deviceFcFile);
/* obtain property_contexts file from running device */
devicePcFile = File.createTempFile("property_contexts", ".tmp");
@@ -130,9 +131,10 @@
/* retrieve the AOSP *_contexts files from jar */
aospSeappFile = copyResourceToTempFile("/general_seapp_contexts");
- aospFcFile = copyResourceToTempFile("/general_file_contexts");
+ aospFcFile = copyResourceToTempFile("/general_file_contexts.bin");
aospPcFile = copyResourceToTempFile("/general_property_contexts");
aospSvcFile = copyResourceToTempFile("/general_service_contexts");
+ seappNeverAllowFile = copyResourceToTempFile("/general_seapp_neverallows");
}
/**
@@ -204,14 +206,12 @@
* @throws Exception
*/
public void testValidSeappContexts() throws Exception {
- File OutputFile = File.createTempFile("seapp_output", ".tmp");
- OutputFile.deleteOnExit();
/* run checkseapp on seapp_contexts */
ProcessBuilder pb = new ProcessBuilder(checkSeapp.getAbsolutePath(),
"-p", devicePolicyFile.getAbsolutePath(),
- deviceSeappFile.getAbsolutePath(),
- "-o", OutputFile.getAbsolutePath());
+ seappNeverAllowFile.getAbsolutePath(),
+ deviceSeappFile.getAbsolutePath());
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
pb.redirectErrorStream(true);
Process p = pb.start();
@@ -257,13 +257,25 @@
}
/**
- * Tests that the file_contexts file on the device contains
+ * Tests that the file_contexts.bin file on the device contains
* the standard AOSP entries.
*
* @throws Exception
*/
public void testAospFileContexts() throws Exception {
- assertFileStartsWith(aospFcFile, deviceFcFile);
+ /* run checkfc -c general_file_contexts.bin file_contexts.bin */
+ ProcessBuilder pb = new ProcessBuilder(checkFc.getAbsolutePath(),
+ "-c", aospFcFile.getAbsolutePath(),
+ deviceFcFile.getAbsolutePath());
+ pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
+ pb.redirectErrorStream(true);
+ Process p = pb.start();
+ p.waitFor();
+ BufferedReader result = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line = result.readLine();
+ assertTrue("The file_contexts.bin file did not include the AOSP entries:\n"
+ + line + "\n",
+ line.equals("equal") || line.equals("subset"));
}
/**
@@ -287,13 +299,13 @@
}
/**
- * Tests that the file_contexts file on the device is valid.
+ * Tests that the file_contexts.bin file on the device is valid.
*
* @throws Exception
*/
public void testValidFileContexts() throws Exception {
- /* run checkfc on file_contexts */
+ /* run checkfc sepolicy file_contexts.bin */
ProcessBuilder pb = new ProcessBuilder(checkFc.getAbsolutePath(),
devicePolicyFile.getAbsolutePath(),
deviceFcFile.getAbsolutePath());
@@ -308,7 +320,7 @@
errorString.append(line);
errorString.append("\n");
}
- assertTrue("The file_contexts file was invalid:\n"
+ assertTrue("The file_contexts.bin file was invalid:\n"
+ errorString, errorString.length() == 0);
}
@@ -345,10 +357,10 @@
*/
public void testValidServiceContexts() throws Exception {
- /* run checkfc -p on service_contexts */
+ /* run checkfc -s on service_contexts */
ProcessBuilder pb = new ProcessBuilder(checkFc.getAbsolutePath(),
- "-p", devicePolicyFile.getAbsolutePath(),
- devicePcFile.getAbsolutePath());
+ "-s", devicePolicyFile.getAbsolutePath(),
+ deviceSvcFile.getAbsolutePath());
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
pb.redirectErrorStream(true);
Process p = pb.start();
@@ -667,15 +679,15 @@
}
/*
- * There will at least be some kernel thread running and all kthreads should
- * be in kernel context.
+ * All kthreads should be in kernel context.
*/
public void testKernelDomain() throws DeviceNotAvailableException {
String domain = "u:r:kernel:s0";
List<ProcessDetails> procs = ProcessDetails.getProcMap(mDevice).get(domain);
- assertNotNull(procs);
- for (ProcessDetails p : procs) {
- assertTrue("Non Kernel thread \"" + p + "\" found!", p.isKernel());
+ if (procs != null) {
+ for (ProcessDetails p : procs) {
+ assertTrue("Non Kernel thread \"" + p + "\" found!", p.isKernel());
+ }
}
}
@@ -715,7 +727,7 @@
tDevice.executeShellCommand("ps -Z", psOut);
String psOutString = psOut.getOutput();
Pattern p = Pattern.compile(
- "^([\\w_:]+)\\s+([\\w_]+)\\s+(\\d+)\\s+(\\d+)\\s+(\\p{Graph}+)$",
+ "^([\\w_:]+)\\s+([\\w_]+)\\s+(\\d+)\\s+(\\d+)\\s+(\\p{Graph}+)\\s*$",
Pattern.MULTILINE);
Matcher m = p.matcher(psOutString);
procMap = new HashMap<String, ArrayList<ProcessDetails>>();
diff --git a/libs/deviceutil/jni/Android.mk b/libs/deviceutil/jni/Android.mk
index b801a4d..e413250 100644
--- a/libs/deviceutil/jni/Android.mk
+++ b/libs/deviceutil/jni/Android.mk
@@ -27,6 +27,7 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog libdl
+LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog libdl
+LOCAL_SDK_VERSION := 19
-include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libs/testserver/src/android/webkit/cts/CtsTestServer.java b/libs/testserver/src/android/webkit/cts/CtsTestServer.java
index de88f3b..d47f89f 100644
--- a/libs/testserver/src/android/webkit/cts/CtsTestServer.java
+++ b/libs/testserver/src/android/webkit/cts/CtsTestServer.java
@@ -54,26 +54,23 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
-import java.net.URLConnection;
-import java.security.KeyManagementException;
import java.security.KeyStore;
-import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Vector;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -81,7 +78,6 @@
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
@@ -115,7 +111,6 @@
private static final String COOKIE_PREFIX = "/cookie";
private static final String LINKED_SCRIPT_PREFIX = "/linkedscriptprefix";
private static final String AUTH_PREFIX = "/auth";
- private static final String SHUTDOWN_PREFIX = "/shutdown";
public static final String NOLENGTH_POSTFIX = "nolength";
private static final int DELAY_MILLIS = 2000;
@@ -223,74 +218,13 @@
* Terminate the http server.
*/
public void shutdown() {
+ mServerThread.shutDownOnClientThread();
+
try {
- // Avoid a deadlock between two threads where one is trying to call
- // close() and the other one is calling accept() by sending a GET
- // request for shutdown and having the server's one thread
- // sequentially call accept() and close().
- URL url = new URL(mServerUri + SHUTDOWN_PREFIX);
- if (url.getProtocol().equalsIgnoreCase("http")) {
- // Use Socket instead of HttpURLConnection when the server is in cleartext HTTP mode
- // to avoid the request being blocked by NetworkSecurityPolicy.
- Socket socket = null;
- try {
- socket = new Socket(url.getHost(), url.getPort());
- socket.getOutputStream().write(
- ("GET " + SHUTDOWN_PREFIX + " HTTP/1.0\r\n\r\n").getBytes("US-ASCII"));
- socket.getOutputStream().flush();
- } finally {
- if (socket != null) {
- try {
- socket.close();
- } catch (Exception ignored) {}
- }
- }
- } else {
- URLConnection connection = openConnection(url);
- connection.connect();
-
- // Read the input from the stream to send the request.
- InputStream is = connection.getInputStream();
- is.close();
- }
-
// Block until the server thread is done shutting down.
mServerThread.join();
-
- } catch (MalformedURLException e) {
- throw new IllegalStateException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (NoSuchAlgorithmException e) {
- throw new IllegalStateException(e);
- } catch (KeyManagementException e) {
- throw new IllegalStateException(e);
- }
- }
-
- private URLConnection openConnection(URL url)
- throws IOException, NoSuchAlgorithmException, KeyManagementException {
- if (mSsl == SslMode.INSECURE) {
- return url.openConnection();
- } else {
- // Install hostname verifiers and trust managers that don't do
- // anything in order to get around the client not trusting
- // the test server due to a lack of certificates.
-
- HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
- connection.setHostnameVerifier(new CtsHostnameVerifier());
-
- SSLContext context = SSLContext.getInstance("TLS");
- try {
- context.init(ServerThread.getKeyManagers(), getTrustManagers(), null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- connection.setSSLSocketFactory(context.getSocketFactory());
-
- return connection;
}
}
@@ -775,11 +709,6 @@
response.setEntity(createPage(agent, agent));
} else if (path.equals(TEST_DOWNLOAD_PATH)) {
response = createTestDownloadResponse(Uri.parse(uriString));
- } else if (path.equals(SHUTDOWN_PREFIX)) {
- response = createResponse(HttpStatus.SC_OK);
- // We cannot close the socket here, because we need to respond.
- // Status must be set to OK, or else the test will fail due to
- // a RunTimeException.
} else if (path.equals(APPCACHE_PATH)) {
response = createResponse(HttpStatus.SC_OK);
response.setEntity(createEntity("<!DOCTYPE HTML>" +
@@ -924,9 +853,12 @@
private CtsTestServer mServer;
private ServerSocket mSocket;
private SslMode mSsl;
- private boolean mIsCancelled;
+ private boolean mWillShutDown = false;
private SSLContext mSslContext;
private ExecutorService mExecutorService = Executors.newFixedThreadPool(20);
+ private Object mLock = new Object();
+ // All the sockets bound to an open connection.
+ private Set<Socket> mSockets = new HashSet<Socket>();
/**
* Defines the keystore contents for the server, BKS version. Holds just a
@@ -1012,10 +944,14 @@
}
public void run() {
- while (!mIsCancelled) {
+ while (!mWillShutDown) {
try {
Socket socket = mSocket.accept();
+ synchronized(mLock) {
+ mSockets.add(socket);
+ }
+
DefaultHttpServerConnection conn = mServer.createHttpServerConnection();
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
@@ -1025,14 +961,11 @@
// parsing the response since conn.close() will crash
// for SSL requests due to UnsupportedOperationException.
HttpRequest request = conn.receiveRequestHeader();
- if (isShutdownRequest(request)) {
- mIsCancelled = true;
- }
if (request instanceof HttpEntityEnclosingRequest) {
conn.receiveRequestEntity( (HttpEntityEnclosingRequest) request);
}
- mExecutorService.execute(new HandleResponseTask(conn, request));
+ mExecutorService.execute(new HandleResponseTask(conn, request, socket));
} catch (IOException e) {
// normal during shutdown, ignore
Log.w(TAG, e);
@@ -1044,10 +977,26 @@
Log.w(TAG, e);
}
}
+ }
+
+ /**
+ * Shutdown the socket and the executor service.
+ * Note this method is called on the client thread, instead of the server thread.
+ */
+ public void shutDownOnClientThread() {
try {
+ mWillShutDown = true;
mExecutorService.shutdown();
mExecutorService.awaitTermination(1L, TimeUnit.MINUTES);
mSocket.close();
+ // To prevent the server thread from being blocked on read from socket,
+ // which is called when the server tries to receiveRequestHeader,
+ // close all the sockets here.
+ synchronized(mLock) {
+ for (Socket socket : mSockets) {
+ socket.close();
+ }
+ }
} catch (IOException ignored) {
// safe to ignore
} catch (InterruptedException e) {
@@ -1055,24 +1004,19 @@
}
}
- private static boolean isShutdownRequest(HttpRequest request) {
- RequestLine requestLine = request.getRequestLine();
- String uriString = requestLine.getUri();
- URI uri = URI.create(uriString);
- String path = uri.getPath();
- return path.equals(SHUTDOWN_PREFIX);
- }
-
private class HandleResponseTask implements Runnable {
private DefaultHttpServerConnection mConnection;
private HttpRequest mRequest;
+ private Socket mSocket;
+
public HandleResponseTask(DefaultHttpServerConnection connection,
- HttpRequest request) {
+ HttpRequest request, Socket socket) {
this.mConnection = connection;
this.mRequest = request;
+ this.mSocket = socket;
}
@Override
@@ -1082,6 +1026,10 @@
mConnection.sendResponseHeader(response);
mConnection.sendResponseEntity(response);
mConnection.close();
+
+ synchronized(mLock) {
+ ServerThread.this.mSockets.remove(mSocket);
+ }
} catch (Exception e) {
Log.e(TAG, "Error handling request:", e);
}
diff --git a/suite/audio_quality/executable/Android.mk b/suite/audio_quality/executable/Android.mk
index a37b987..8049596 100644
--- a/suite/audio_quality/executable/Android.mk
+++ b/suite/audio_quality/executable/Android.mk
@@ -14,23 +14,15 @@
# limitations under the License.
#
-# build only for linux
-ifeq ($(HOST_OS),linux)
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_CPP_EXTENSION := .cpp
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(patsubst ./%,%, $(shell cd $(LOCAL_PATH); \
- find . -name "*.cpp" -and -not -name ".*"))
-#$(info $(LOCAL_SRC_FILES))
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lib/include external/tinyalsa/include/ libcore/include \
$(LOCAL_PATH)/../lib/src
LOCAL_STATIC_LIBRARIES += libutils liblog libcutils libtinyalsa libtinyxml
LOCAL_WHOLE_STATIC_LIBRARIES := libcts_audio_quality
LOCAL_CFLAGS:= -g -fno-exceptions
LOCAL_LDFLAGS:= -g -lrt -ldl -lstdc++ -lm -fno-exceptions -lpthread
+LOCAL_MODULE_HOST_OS := linux
LOCAL_MODULE:= cts_audio_quality
include $(BUILD_HOST_EXECUTABLE)
-
-endif # linux
diff --git a/suite/audio_quality/lib/Android.mk b/suite/audio_quality/lib/Android.mk
index 341a4dd..d4aaf84 100644
--- a/suite/audio_quality/lib/Android.mk
+++ b/suite/audio_quality/lib/Android.mk
@@ -14,22 +14,14 @@
# limitations under the License.
#
-# build only for linux
-ifeq ($(HOST_OS),linux)
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_CPP_EXTENSION := .cpp
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(patsubst ./%,%, $(shell cd $(LOCAL_PATH); \
- find . -name "*.cpp" -and -not -name ".*"))
-#$(info $(LOCAL_SRC_FILES))
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/src /usr/include/ \
external/tinyalsa/include/ external/tinyxml/ libcore/include
LOCAL_STATIC_LIBRARIES += libutils liblog libtinyalsa libcutils libtinyxml
LOCAL_CFLAGS:= -g -fno-exceptions
LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions
+LOCAL_MODULE_HOST_OS := linux
LOCAL_MODULE:= libcts_audio_quality
include $(BUILD_HOST_STATIC_LIBRARY)
-
-endif # linux
diff --git a/suite/audio_quality/lib/include/Log.h b/suite/audio_quality/lib/include/Log.h
index d7520f0..b33c21f 100644
--- a/suite/audio_quality/lib/include/Log.h
+++ b/suite/audio_quality/lib/include/Log.h
@@ -64,6 +64,6 @@
#define ASSERT(cond) if(!(cond)) { Log::Instance()->printf(Log::ELogE, \
"assertion failed %s %d", __FILE__, __LINE__); \
Log::Finalize(); \
- *(char*)0 = 0; /* this will crash */};
+ abort(); };
#endif // CTSAUDIO_LOG_H
diff --git a/suite/audio_quality/lib/src/FileUtil.cpp b/suite/audio_quality/lib/src/FileUtil.cpp
index dffc394..3b87016 100644
--- a/suite/audio_quality/lib/src/FileUtil.cpp
+++ b/suite/audio_quality/lib/src/FileUtil.cpp
@@ -81,7 +81,7 @@
mBuffer = new char[DEFAULT_BUFFER_SIZE];
if (mBuffer == NULL) {
// cannot use ASSERT here, just crash
- *(char*)0 = 0;
+ abort();
}
mBufferSize = DEFAULT_BUFFER_SIZE;
}
@@ -130,7 +130,7 @@
mBuffer = new char[2 * size];
if (mBuffer == NULL) {
// cannot use ASSERT here, just crash
- *(char*)0 = 0;
+ abort();
}
mBufferSize = 2 * size;
// re-try
diff --git a/suite/audio_quality/lib/src/Log.cpp b/suite/audio_quality/lib/src/Log.cpp
index d4cf353..1d2434a 100644
--- a/suite/audio_quality/lib/src/Log.cpp
+++ b/suite/audio_quality/lib/src/Log.cpp
@@ -23,7 +23,7 @@
#define ASSERT_PLAIN(cond) if(!(cond)) { fprintf(stderr, \
"assertion failed %s %d", __FILE__, __LINE__); \
- *(char*)0 = 0; /* this will crash */};
+ abort(); };
Log* Log::Instance(const char* dirName)
{
diff --git a/suite/audio_quality/test/Android.mk b/suite/audio_quality/test/Android.mk
index bd0033f..21b0250 100644
--- a/suite/audio_quality/test/Android.mk
+++ b/suite/audio_quality/test/Android.mk
@@ -14,16 +14,9 @@
# limitations under the License.
#
-# build only for linux
-ifeq ($(HOST_OS),linux)
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_CPP_EXTENSION := .cpp
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(patsubst ./%,%, $(shell cd $(LOCAL_PATH); \
- find . -name "*.cpp" -and -not -name ".*"))
-#LOCAL_SRC_FILES := AudioRecordPlayTest.cpp
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
#$(info $(LOCAL_SRC_FILES))
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lib/include $(LOCAL_PATH)/../lib/src external/gtest/include \
@@ -35,7 +28,6 @@
LOCAL_WHOLE_STATIC_LIBRARIES := libcts_audio_quality
LOCAL_CFLAGS:= -g -fno-exceptions
LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions -lpthread
+LOCAL_MODULE_HOST_OS := linux
LOCAL_MODULE:= cts_audio_quality_test
include $(BUILD_HOST_EXECUTABLE)
-
-endif # linux
diff --git a/suite/cts/deviceTests/opengl/jni/Android.mk b/suite/cts/deviceTests/opengl/jni/Android.mk
index 7b58170..01d0721 100644
--- a/suite/cts/deviceTests/opengl/jni/Android.mk
+++ b/suite/cts/deviceTests/opengl/jni/Android.mk
@@ -18,14 +18,11 @@
LOCAL_MODULE := libctsopengl_jni
-LOCAL_MODULE_TAGS := optional
-
# Needed in order to use fences for synchronization
LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES -funsigned-char
# Get all cpp files but not hidden files
-LOCAL_SRC_FILES := $(patsubst ./%,%, $(shell cd $(LOCAL_PATH); \
- find . -name "*.cpp" -and -not -name ".*"))
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/suite/cts/deviceTests/opengl/test/Android.mk b/suite/cts/deviceTests/opengl/test/Android.mk
index 5270bac..e83e584 100644
--- a/suite/cts/deviceTests/opengl/test/Android.mk
+++ b/suite/cts/deviceTests/opengl/test/Android.mk
@@ -13,23 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# build only for linux
-ifeq ($(HOST_OS),linux)
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(patsubst ./%,%, $(shell cd $(LOCAL_PATH); \
- find . -name "*.cpp" -and -not -name ".*"))
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
LOCAL_SRC_FILES += ../jni/graphics/Matrix.cpp
-#$(info $(LOCAL_SRC_FILES))
LOCAL_C_INCLUDES += external/gtest/include $(LOCAL_PATH)/../jni/graphics/
LOCAL_STATIC_LIBRARIES := libgtest_host libgtest_main_host liblog
LOCAL_LDFLAGS:= -g -lpthread
+LOCAL_MODULE_HOST_OS := linux
LOCAL_MODULE:= cts_device_opengl_test
include $(BUILD_HOST_EXECUTABLE)
-
-endif # linux
diff --git a/suite/cts/deviceTests/videoperf/Android.mk b/suite/cts/deviceTests/videoperf/Android.mk
index b589475..4b825c5 100644
--- a/suite/cts/deviceTests/videoperf/Android.mk
+++ b/suite/cts/deviceTests/videoperf/Android.mk
@@ -25,7 +25,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctsmediautil ctsdeviceutil ctstestrunner
-LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java b/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
index 62f37c5..39f3cb4 100644
--- a/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
+++ b/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
@@ -912,7 +912,7 @@
}
/**
- * run encoder benchmarking with encoded stream stored from encoding phase
+ * run decoder benchmarking with encoded stream stored from encoding phase
* @param decoderName decoder name
* @param format format of media to decode
* @return returns length-2 array with 0: time for decoding, 1 : rms error of pixels
diff --git a/suite/cts/hostTests/jank/Android.mk b/suite/cts/hostTests/jank/Android.mk
index a1f4d90..8f1be07 100644
--- a/suite/cts/hostTests/jank/Android.mk
+++ b/suite/cts/hostTests/jank/Android.mk
@@ -33,7 +33,7 @@
$(cts_library_jar_): $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_DEVICE_JAR_))/javalib.jar | $(ACP)
$(hide) mkdir -p $(CTS_TESTCASES_OUT)
- $(hide) $(ACP) -fp $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_DEVICE_JAR_))/javalib.jar $@
+ $(hide) $(ACP) -fp $< $@
$(CTS_TESTCASES_OUT)/CtsHostJank.xml: $(cts_library_jar_)
diff --git a/tests/core/ctscore.mk b/tests/core/ctscore.mk
index fea0b07..10a91f1 100644
--- a/tests/core/ctscore.mk
+++ b/tests/core/ctscore.mk
@@ -23,7 +23,10 @@
# Don't delete META-INF from the core-tests jar
LOCAL_DONT_DELETE_JAR_META_INF := true
-LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests
+# TODO: Clean up this mess. (b/26483949). libnativehelper_compat_libc++ pulls in its own
+# static copy of libc++ and the libc++ we're bundling here is the platform libc++. This is
+# bround to break but is being submitted as a workaround for failing CTS tests.
+LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests libsqlite_jni libnativehelper_compat_libc++ libc++
# Include both the 32 and 64 bit versions of libjavacoretests,
# where applicable.
diff --git a/tests/core/libcore/libcore/Android.mk b/tests/core/libcore/libcore/Android.mk
index a86d2c0..d8e3fcb 100644
--- a/tests/core/libcore/libcore/Android.mk
+++ b/tests/core/libcore/libcore/Android.mk
@@ -16,5 +16,5 @@
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.libcore
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests mockito-target
include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java b/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
index 65f89f3..9f66e15 100644
--- a/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
@@ -44,25 +44,25 @@
final Point min = getScreenSize();
final int w = min.x * 3;
final int h = min.y * 2;
-
assertDesiredMinimum(new Point(min.x / 2, min.y / 2), min);
- assertDesiredMinimum(new Point(w, h),
- new Point(w, h));
+ assertDesiredMinimum(new Point(w, h), min);
- assertDesiredMinimum(new Point(min.x / 2, h),
- new Point(min.x, h));
+ assertDesiredMinimum(new Point(min.x / 2, h), min);
- assertDesiredMinimum(new Point(w, min.y / 2),
- new Point(w, min.y));
+ assertDesiredMinimum(new Point(w, min.y / 2), min);
}
- private void assertDesiredMinimum(Point suggestedSize, Point expectedSize) {
+ private void assertDesiredMinimum(Point suggestedSize, Point minSize) {
mWallpaperManager.suggestDesiredDimensions(suggestedSize.x, suggestedSize.y);
Point actualSize = new Point(mWallpaperManager.getDesiredMinimumWidth(),
mWallpaperManager.getDesiredMinimumHeight());
if (actualSize.x > 0 || actualSize.y > 0) {
- assertEquals(expectedSize, actualSize);
+ if((actualSize.x < minSize.x || actualSize.y < minSize.y)){
+ throw new AssertionError("Expected at least x: " + minSize.x + " y: "
+ + minSize.y + ", got x: " + actualSize.x +
+ " y: " + actualSize.y );
+ }
}
}
diff --git a/tests/tests/content/src/android/content/cts/DummyProvider.java b/tests/tests/content/src/android/content/cts/DummyProvider.java
index 9c50cb9..926ec1d 100644
--- a/tests/tests/content/src/android/content/cts/DummyProvider.java
+++ b/tests/tests/content/src/android/content/cts/DummyProvider.java
@@ -16,8 +16,6 @@
package android.content.cts;
-import dalvik.annotation.TestTargetClass;
-
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
@@ -33,7 +31,6 @@
* @see AsyncQueryHandlerTest
* @see ContentQueryMapTest
*/
-@TestTargetClass(ContentProvider.class)
public class DummyProvider extends ContentProvider {
private static final String MOCK_OPERATION = "mockOperation";
diff --git a/tests/tests/drm/jni/Android.mk b/tests/tests/drm/jni/Android.mk
index 06b2df9..87f00a4 100644
--- a/tests/tests/drm/jni/Android.mk
+++ b/tests/tests/drm/jni/Android.mk
@@ -28,5 +28,6 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
LOCAL_SHARED_LIBRARIES := liblog libdl
+LOCAL_SDK_VERSION := 23
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/drm/jni/android_drm_cts_NativeCodeTest.cpp b/tests/tests/drm/jni/android_drm_cts_NativeCodeTest.cpp
index e5c9f960..9fe4bb2 100644
--- a/tests/tests/drm/jni/android_drm_cts_NativeCodeTest.cpp
+++ b/tests/tests/drm/jni/android_drm_cts_NativeCodeTest.cpp
@@ -15,11 +15,11 @@
*/
#include <jni.h>
-#include <sys/types.h>
+#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <sys/syscall.h>
-#include <utils/Log.h>
+#include <sys/types.h>
+#include <unistd.h>
/*
* Returns true iff this device may be vulnerable to installation of rogue drm
diff --git a/tests/tests/jni/Android.mk b/tests/tests/jni/Android.mk
index 1aeb8b7..7d55698 100644
--- a/tests/tests/jni/Android.mk
+++ b/tests/tests/jni/Android.mk
@@ -29,7 +29,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
-LOCAL_JNI_SHARED_LIBRARIES := libjnitest
+LOCAL_JNI_SHARED_LIBRARIES := libjnitest libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/jni/libjnitest/Android.mk b/tests/tests/jni/libjnitest/Android.mk
index 396e161..7a2d577 100644
--- a/tests/tests/jni/libjnitest/Android.mk
+++ b/tests/tests/jni/libjnitest/Android.mk
@@ -36,6 +36,9 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog
+LOCAL_SHARED_LIBRARIES := liblog libnativehelper_compat_libc++
+
+LOCAL_SDK_VERSION := 23
+LOCAL_NDK_STL_VARIANT := c++_static
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/jni/libjnitest/helper.c b/tests/tests/jni/libjnitest/helper.c
index 831d5b5..8f7f2f8 100644
--- a/tests/tests/jni/libjnitest/helper.c
+++ b/tests/tests/jni/libjnitest/helper.c
@@ -16,9 +16,10 @@
#include "helper.h"
-#include <cutils/log.h>
+#include <android/log.h>
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#define LOG_TAG "cts"
@@ -29,7 +30,7 @@
char *result;
va_start(args, format);
- LOG_PRI_VA(ANDROID_LOG_ERROR, LOG_TAG, format, args);
+ __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, format, args);
va_end(args);
va_start(args, format);
@@ -58,7 +59,7 @@
JniTestFunction *function = va_arg(args, JniTestFunction *);
- ALOGI("running %s", name);
+ __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "running %s", name);
char *oneResult = function(env);
if (oneResult != NULL) {
diff --git a/tests/tests/jni/libjnitest/register.c b/tests/tests/jni/libjnitest/register.c
index 66eb265..b371b8b 100644
--- a/tests/tests/jni/libjnitest/register.c
+++ b/tests/tests/jni/libjnitest/register.c
@@ -14,10 +14,12 @@
* limitations under the License.
*/
-#include <cutils/log.h>
+#include <android/log.h>
#include <jni.h>
#include <stdlib.h>
+#define LOG_TAG "Cts-JniTest"
+
/*
* This function is called automatically by the system when this
* library is loaded. We use it to register all our native functions,
@@ -32,25 +34,25 @@
extern int register_InstanceNonce(JNIEnv *);
if (register_InstanceNonce(env)) {
- ALOGE("failed to register InstanceNonce");
+ __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "failed to register InstanceNonce");
return JNI_ERR;
}
extern int register_StaticNonce(JNIEnv *);
if (register_StaticNonce(env)) {
- ALOGE("failed to register StaticNonce");
+ __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "failed to register StaticNonce");
return JNI_ERR;
}
extern int register_JniCTest(JNIEnv *);
if (register_JniCTest(env)) {
- ALOGE("failed to register JniCTest");
+ __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "failed to register JniCTest");
return JNI_ERR;
}
extern int register_JniCppTest(JNIEnv *);
if (register_JniCppTest(env)) {
- ALOGE("failed to register JniCppTest");
+ __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "failed to register JniCppTest");
return JNI_ERR;
}
diff --git a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
index 5fe3505..f7cc586 100644
--- a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
@@ -16,6 +16,8 @@
package android.keystore.cts;
+import android.app.KeyguardManager;
+import android.content.Context;
import android.security.KeyPairGeneratorSpec;
import android.security.KeyStoreParameter;
import android.security.keystore.KeyProperties;
@@ -1334,6 +1336,14 @@
}
public void testKeyStore_SetEntry_PrivateKeyEntry_Params_Unencrypted_Failure() throws Exception {
+ // This test asserts that Android Keystore refuses to create/import keys encrypted at rest
+ // using the secure lock screen credential. The test assumes that the secure lock screen is
+ // not set up.
+ KeyguardManager keyguardManager =
+ (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
+ assertNotNull(keyguardManager);
+ assertFalse("Secure lock screen must not be configured", keyguardManager.isDeviceSecure());
+
mKeyStore.load(null, null);
KeyFactory keyFact = KeyFactory.getInstance("RSA");
diff --git a/tests/tests/keystore/src/android/keystore/cts/CipherTest.java b/tests/tests/keystore/src/android/keystore/cts/CipherTest.java
index e2c1d69..1a24fb2 100644
--- a/tests/tests/keystore/src/android/keystore/cts/CipherTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/CipherTest.java
@@ -441,12 +441,24 @@
if (!"SHA-1".equalsIgnoreCase(
((MGF1ParameterSpec) spec.getMGFParameters())
.getDigestAlgorithm())) {
+ // Create a new instance of Cipher because Bouncy Castle's RSA Cipher
+ // caches AlgorithmParameters returned by Cipher.getParameters and does
+ // not invalidate the cache when reinitialized with different
+ // parameters.
+ cipher = Cipher.getInstance(algorithm, encryptionProvider);
cipher.init(Cipher.ENCRYPT_MODE, encryptionKey, new OAEPParameterSpec(
spec.getDigestAlgorithm(),
"MGF1",
MGF1ParameterSpec.SHA1,
PSource.PSpecified.DEFAULT));
params = cipher.getParameters();
+ OAEPParameterSpec newSpec =
+ params.getParameterSpec(OAEPParameterSpec.class);
+ assertEquals(spec.getDigestAlgorithm(), newSpec.getDigestAlgorithm());
+ assertEquals(
+ "SHA-1",
+ ((MGF1ParameterSpec) newSpec.getMGFParameters())
+ .getDigestAlgorithm());
}
}
diff --git a/tests/tests/keystore/src/android/keystore/cts/RSASignatureTest.java b/tests/tests/keystore/src/android/keystore/cts/RSASignatureTest.java
index 9ae3043..e28fdff 100644
--- a/tests/tests/keystore/src/android/keystore/cts/RSASignatureTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/RSASignatureTest.java
@@ -163,7 +163,7 @@
R.raw.rsa_key6_768_pkcs8, R.raw.rsa_key6_768_cert, importParams),
TestUtils.importIntoAndroidKeyStore("testRSA1024", context,
R.raw.rsa_key3_1024_pkcs8, R.raw.rsa_key3_1024_cert, importParams),
- TestUtils.importIntoAndroidKeyStore("testRSA2024", context,
+ TestUtils.importIntoAndroidKeyStore("testRSA2048", context,
R.raw.rsa_key8_2048_pkcs8, R.raw.rsa_key8_2048_cert, importParams),
TestUtils.importIntoAndroidKeyStore("testRSA3072", context,
R.raw.rsa_key7_3072_pksc8, R.raw.rsa_key7_3072_cert, importParams),
diff --git a/tests/tests/keystore/src/android/keystore/cts/SignatureTest.java b/tests/tests/keystore/src/android/keystore/cts/SignatureTest.java
index 8451eb8..6fb3954 100644
--- a/tests/tests/keystore/src/android/keystore/cts/SignatureTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/SignatureTest.java
@@ -562,8 +562,7 @@
}
}
- // TODO: Re-enable this test once Signature.initSign passes SecureRandom to SPI (Bug 22485587).
- public void DISABLED_testEntropyConsumption() throws Exception {
+ public void testEntropyConsumption() throws Exception {
// Assert that signature generation consumes the correct amount of entropy from the provided
// SecureRandom. There is no need to check that Signature.verify does not consume entropy
// because Signature.initVerify does not take a SecureRandom.
diff --git a/tests/tests/keystore/src/android/keystore/cts/TestUtils.java b/tests/tests/keystore/src/android/keystore/cts/TestUtils.java
index 85b8869..2c87005 100644
--- a/tests/tests/keystore/src/android/keystore/cts/TestUtils.java
+++ b/tests/tests/keystore/src/android/keystore/cts/TestUtils.java
@@ -744,7 +744,8 @@
if (KeyProperties.SIGNATURE_PADDING_RSA_PKCS1.equalsIgnoreCase(paddingScheme)) {
paddingOverheadBytes = 30;
} else if (KeyProperties.SIGNATURE_PADDING_RSA_PSS.equalsIgnoreCase(paddingScheme)) {
- paddingOverheadBytes = 22;
+ int saltSizeBytes = (digestOutputSizeBits + 7) / 8;
+ paddingOverheadBytes = saltSizeBytes + 1;
} else {
throw new IllegalArgumentException(
"Unsupported signature padding scheme: " + paddingScheme);
diff --git a/tests/tests/media/Android.mk b/tests/tests/media/Android.mk
index ea7256d..a911ea5 100644
--- a/tests/tests/media/Android.mk
+++ b/tests/tests/media/Android.mk
@@ -41,7 +41,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := \
ctsmediautil ctsdeviceutil ctstestserver ctstestrunner
-LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni libaudio_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni libaudio_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/media/libmediandkjni/Android.mk b/tests/tests/media/libmediandkjni/Android.mk
index 23f9f5c..51210af 100644
--- a/tests/tests/media/libmediandkjni/Android.mk
+++ b/tests/tests/media/libmediandkjni/Android.mk
@@ -30,6 +30,8 @@
LOCAL_C_INCLUDES += $(call include-path-for, mediandk)
-LOCAL_SHARED_LIBRARIES := libandroid libnativehelper liblog libmediandk
+LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog libmediandk
+
+LOCAL_SDK_VERSION := 23
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/media/libmediandkjni/native-media-jni.cpp b/tests/tests/media/libmediandkjni/native-media-jni.cpp
index 2624c25..f15a196 100644
--- a/tests/tests/media/libmediandkjni/native-media-jni.cpp
+++ b/tests/tests/media/libmediandkjni/native-media-jni.cpp
@@ -30,11 +30,11 @@
#include <android/native_window_jni.h>
-#include "ndk/NdkMediaExtractor.h"
-#include "ndk/NdkMediaCodec.h"
-#include "ndk/NdkMediaCrypto.h"
-#include "ndk/NdkMediaFormat.h"
-#include "ndk/NdkMediaMuxer.h"
+#include "media/NdkMediaExtractor.h"
+#include "media/NdkMediaCodec.h"
+#include "media/NdkMediaCrypto.h"
+#include "media/NdkMediaFormat.h"
+#include "media/NdkMediaMuxer.h"
template <class T>
class simplevector {
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index 75a5a13..861df41 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -294,6 +294,43 @@
}
}
+ public void testPlayAudioLooping() throws Exception {
+ final int resid = R.raw.testmp3;
+
+ MediaPlayer mp = MediaPlayer.create(mContext, resid);
+ try {
+ mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ mp.setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
+ mp.setLooping(true);
+ mOnCompletionCalled.reset();
+ mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mp) {
+ Log.i("@@@", "got oncompletion");
+ mOnCompletionCalled.signal();
+ }
+ });
+
+ assertFalse(mp.isPlaying());
+ mp.start();
+ assertTrue(mp.isPlaying());
+
+ int duration = mp.getDuration();
+ Thread.sleep(duration * 4); // allow for several loops
+ assertTrue(mp.isPlaying());
+ assertEquals("wrong number of completion signals", 0, mOnCompletionCalled.getNumSignal());
+ mp.setLooping(false);
+
+ // wait for playback to finish
+ while(mp.isPlaying()) {
+ Thread.sleep(SLEEP_TIME);
+ }
+ assertEquals("wrong number of completion signals", 1, mOnCompletionCalled.getNumSignal());
+ } finally {
+ mp.release();
+ }
+ }
+
public void testPlayMidi() throws Exception {
final int resid = R.raw.midi8sec;
final int midiDuration = 8000;
diff --git a/tests/tests/nativeopengl/libnativeopengltests/Android.mk b/tests/tests/nativeopengl/libnativeopengltests/Android.mk
index 62e28ec..9338d8b 100644
--- a/tests/tests/nativeopengl/libnativeopengltests/Android.mk
+++ b/tests/tests/nativeopengl/libnativeopengltests/Android.mk
@@ -16,26 +16,28 @@
# This is the shared library included by the JNI test app.
#
-LOCAL_PATH := $(call my-dir)/../standalone/jni/
-REAL_LOCAL_PATH := $(call my-dir)
+LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(REAL_LOCAL_PATH)/Android.mk
-
LOCAL_MODULE := libnativeopengltests
# Don't include this package in any configuration by default.
LOCAL_MODULE_TAGS := optional
-LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) \
- external/gtest/include \
+my_src_dir := ../standalone/jni
-LOCAL_SRC_FILES := \
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/$(my_src_dir) \
+ external/gtest/include
+
+# The sources are in ../standalone/jni/
+LOCAL_SRC_FILES := $(addprefix $(my_src_dir)/, \
register.cpp \
GLTestHelper.cpp \
tests/GLTest_test.cpp \
tests/EGLCleanup_test.cpp \
- tests/EGLCreateContext_test.cpp
+ tests/EGLCreateContext_test.cpp \
+ )
LOCAL_CXX_STL := libc++
LOCAL_SHARED_LIBRARIES := libEGL \
@@ -45,4 +47,6 @@
LOCAL_STATIC_LIBRARIES := libgtest
+my_src_dir :=
+
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/net/Android.mk b/tests/tests/net/Android.mk
index 6524871..56729b6 100644
--- a/tests/tests/net/Android.mk
+++ b/tests/tests/net/Android.mk
@@ -27,7 +27,7 @@
LOCAL_JAVA_LIBRARIES := voip-common conscrypt org.apache.http.legacy
LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libnativedns_jni \
- libnativemultinetwork_jni
+ libnativemultinetwork_jni libnativehelper_compat_libc++
# include CtsTestServer as a temporary hack to free net.cts from cts.stub.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/net/jni/Android.mk b/tests/tests/net/jni/Android.mk
index ca82b30..0ec8d28 100644
--- a/tests/tests/net/jni/Android.mk
+++ b/tests/tests/net/jni/Android.mk
@@ -25,8 +25,8 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog
-
+LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog
+LOCAL_CXX_STL := libc++_static
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
@@ -35,5 +35,6 @@
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := NativeMultinetworkJni.c
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libandroid libnativehelper liblog
+LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog
+LOCAL_CXX_STL := libc++_static
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/net/src/android/net/cts/LocalServerSocketTest.java b/tests/tests/net/src/android/net/cts/LocalServerSocketTest.java
index dc7be1f..103d1da 100644
--- a/tests/tests/net/src/android/net/cts/LocalServerSocketTest.java
+++ b/tests/tests/net/src/android/net/cts/LocalServerSocketTest.java
@@ -15,28 +15,27 @@
*/
package android.net.cts;
+import junit.framework.TestCase;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
-import android.test.AndroidTestCase;
-public class LocalServerSocketTest extends AndroidTestCase {
+public class LocalServerSocketTest extends TestCase {
public void testLocalServerSocket() throws IOException {
- LocalServerSocket localServerSocket = new LocalServerSocket(LocalSocketTest.mSockAddr);
+ String address = "com.android.net.LocalServerSocketTest_testLocalServerSocket";
+ LocalServerSocket localServerSocket = new LocalServerSocket(address);
assertNotNull(localServerSocket.getLocalSocketAddress());
- commonFunctions(localServerSocket);
- }
- public void commonFunctions(LocalServerSocket localServerSocket) throws IOException {
// create client socket
LocalSocket clientSocket = new LocalSocket();
// establish connection between client and server
- clientSocket.connect(new LocalSocketAddress(LocalSocketTest.mSockAddr));
+ clientSocket.connect(new LocalSocketAddress(address));
LocalSocket serverSocket = localServerSocket.accept();
// send data from client to server
diff --git a/tests/tests/net/src/android/net/cts/LocalSocketTest.java b/tests/tests/net/src/android/net/cts/LocalSocketTest.java
index 865ec21..77f0a44 100644
--- a/tests/tests/net/src/android/net/cts/LocalSocketTest.java
+++ b/tests/tests/net/src/android/net/cts/LocalSocketTest.java
@@ -16,26 +16,31 @@
package android.net.cts;
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import junit.framework.TestCase;
+
import android.net.Credentials;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
-import android.test.AndroidTestCase;
-public class LocalSocketTest extends AndroidTestCase{
- public final static String mSockAddr = "com.android.net.LocalSocketTest";
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
- public void testLocalConnections() throws IOException{
+public class LocalSocketTest extends TestCase {
+ private final static String ADDRESS_PREFIX = "com.android.net.LocalSocketTest";
+
+ public void testLocalConnections() throws IOException {
+ String address = ADDRESS_PREFIX + "_testLocalConnections";
// create client and server socket
- LocalServerSocket localServerSocket = new LocalServerSocket(mSockAddr);
+ LocalServerSocket localServerSocket = new LocalServerSocket(address);
LocalSocket clientSocket = new LocalSocket();
// establish connection between client and server
- LocalSocketAddress locSockAddr = new LocalSocketAddress(mSockAddr);
+ LocalSocketAddress locSockAddr = new LocalSocketAddress(address);
assertFalse(clientSocket.isConnected());
clientSocket.connect(locSockAddr);
assertTrue(clientSocket.isConnected());
@@ -111,9 +116,10 @@
}
}
- public void testAccessors() throws IOException{
+ public void testAccessors() throws IOException {
+ String address = ADDRESS_PREFIX + "_testAccessors";
LocalSocket socket = new LocalSocket();
- LocalSocketAddress addr = new LocalSocketAddress("secondary");
+ LocalSocketAddress addr = new LocalSocketAddress(address);
assertFalse(socket.isBound());
socket.bind(addr);
@@ -129,9 +135,9 @@
socket.setSendBufferSize(3998);
assertEquals(3998 << 1, socket.getSendBufferSize());
- // Timeout is not support at present, so set is ignored
- socket.setSoTimeout(1996);
assertEquals(0, socket.getSoTimeout());
+ socket.setSoTimeout(1996);
+ assertTrue(socket.getSoTimeout() > 0);
try {
socket.getRemoteSocketAddress();
@@ -167,5 +173,127 @@
} catch (UnsupportedOperationException e) {
// expected
}
+
+ socket.close();
+ }
+
+ public void testAvailable() throws Exception {
+ String address = ADDRESS_PREFIX + "_testAvailable";
+ LocalServerSocket localServerSocket = new LocalServerSocket(address);
+ LocalSocket clientSocket = new LocalSocket();
+
+ // establish connection between client and server
+ LocalSocketAddress locSockAddr = new LocalSocketAddress(address);
+ clientSocket.connect(locSockAddr);
+ assertTrue(clientSocket.isConnected());
+ LocalSocket serverSocket = localServerSocket.accept();
+
+ OutputStream clientOutputStream = clientSocket.getOutputStream();
+ InputStream serverInputStream = serverSocket.getInputStream();
+ assertEquals(0, serverInputStream.available());
+
+ byte[] buffer = new byte[50];
+ clientOutputStream.write(buffer);
+ assertEquals(50, serverInputStream.available());
+
+ InputStream clientInputStream = clientSocket.getInputStream();
+ OutputStream serverOutputStream = serverSocket.getOutputStream();
+ assertEquals(0, clientInputStream.available());
+ serverOutputStream.write(buffer);
+ assertEquals(50, serverInputStream.available());
+
+ clientSocket.close();
+ serverSocket.close();
+ localServerSocket.close();
+ }
+
+ public void testFlush() throws Exception {
+ String address = ADDRESS_PREFIX + "_testFlush";
+ LocalServerSocket localServerSocket = new LocalServerSocket(address);
+ LocalSocket clientSocket = new LocalSocket();
+
+ // establish connection between client and server
+ LocalSocketAddress locSockAddr = new LocalSocketAddress(address);
+ clientSocket.connect(locSockAddr);
+ assertTrue(clientSocket.isConnected());
+ LocalSocket serverSocket = localServerSocket.accept();
+
+ OutputStream clientOutputStream = clientSocket.getOutputStream();
+ InputStream serverInputStream = serverSocket.getInputStream();
+ testFlushWorks(clientOutputStream, serverInputStream);
+
+ OutputStream serverOutputStream = serverSocket.getOutputStream();
+ InputStream clientInputStream = clientSocket.getInputStream();
+ testFlushWorks(serverOutputStream, clientInputStream);
+
+ clientSocket.close();
+ serverSocket.close();
+ localServerSocket.close();
+ }
+
+ private void testFlushWorks(OutputStream outputStream, InputStream inputStream)
+ throws Exception {
+ final int bytesToTransfer = 50;
+ StreamReader inputStreamReader = new StreamReader(inputStream, bytesToTransfer);
+
+ byte[] buffer = new byte[bytesToTransfer];
+ outputStream.write(buffer);
+ assertEquals(bytesToTransfer, inputStream.available());
+
+ // Start consuming the data.
+ inputStreamReader.start();
+
+ // This doesn't actually flush any buffers, it just polls until the reader has read all the
+ // bytes.
+ outputStream.flush();
+
+ inputStreamReader.waitForCompletion(5000);
+ inputStreamReader.assertBytesRead(bytesToTransfer);
+ assertEquals(0, inputStream.available());
+ }
+
+ private static class StreamReader extends Thread {
+ private final InputStream is;
+ private final int expectedByteCount;
+ private final CountDownLatch completeLatch = new CountDownLatch(1);
+
+ private volatile Exception exception;
+ private int bytesRead;
+
+ private StreamReader(InputStream is, int expectedByteCount) {
+ this.is = is;
+ this.expectedByteCount = expectedByteCount;
+ }
+
+ @Override
+ public void run() {
+ try {
+ byte[] buffer = new byte[10];
+ int readCount;
+ while ((readCount = is.read(buffer)) >= 0) {
+ bytesRead += readCount;
+ if (bytesRead >= expectedByteCount) {
+ break;
+ }
+ }
+ } catch (IOException e) {
+ exception = e;
+ } finally {
+ completeLatch.countDown();
+ }
+ }
+
+ public void waitForCompletion(long waitMillis) throws Exception {
+ if (!completeLatch.await(waitMillis, TimeUnit.MILLISECONDS)) {
+ fail("Timeout waiting for completion");
+ }
+ if (exception != null) {
+ throw new Exception("Read failed", exception);
+ }
+ }
+
+ public void assertBytesRead(int expected) {
+ assertEquals(expected, bytesRead);
+ }
}
}
diff --git a/tests/tests/net/src/android/net/wifi/cts/ConcurrencyTest.java b/tests/tests/net/src/android/net/wifi/cts/ConcurrencyTest.java
index 5accd77..343c1e6 100644
--- a/tests/tests/net/src/android/net/wifi/cts/ConcurrencyTest.java
+++ b/tests/tests/net/src/android/net/wifi/cts/ConcurrencyTest.java
@@ -94,8 +94,8 @@
}
mContext.unregisterReceiver(mReceiver);
- if (mWifiManager.isWifiEnabled()) {
- assertTrue(mWifiManager.setWifiEnabled(false));
+ if (!mWifiManager.isWifiEnabled()) {
+ assertTrue(mWifiManager.setWifiEnabled(true));
Thread.sleep(DURATION);
}
super.tearDown();
diff --git a/tests/tests/net/src/org/apache/http/conn/ssl/cts/AbstractVerifierTest.java b/tests/tests/net/src/org/apache/http/conn/ssl/cts/AbstractVerifierTest.java
new file mode 100644
index 0000000..16d3ac4
--- /dev/null
+++ b/tests/tests/net/src/org/apache/http/conn/ssl/cts/AbstractVerifierTest.java
@@ -0,0 +1,306 @@
+/*
+ * Copyright (C) 2010 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 org.apache.http.conn.ssl.cts;
+
+import javax.security.auth.x500.X500Principal;
+import junit.framework.TestCase;
+
+import org.apache.http.conn.ssl.AbstractVerifier;
+
+import java.lang.Override;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * See also {@link libcore.javax.security.auth.x500.X500PrincipalTest} as it shows some cases
+ * we are not checking as they are not allowed by the X500 principal in the first place.
+ */
+public final class AbstractVerifierTest extends TestCase {
+
+ public void testGetCns() {
+ assertCns("");
+ assertCns("ou=xxx");
+ assertCns("ou=xxx,cn=xxx", "xxx");
+ assertCns("ou=xxx+cn=yyy,cn=zzz+cn=abc", "yyy", "zzz", "abc");
+ assertCns("cn=a,cn=b", "a", "b");
+ assertCns("cn=a c,cn=b", "a c", "b");
+ assertCns("cn=a ,cn=b", "a", "b");
+ assertCns("cn=Cc,cn=Bb,cn=Aa", "Cc", "Bb", "Aa");
+ assertCns("cn=imap.gmail.com", "imap.gmail.com");
+ assertCns("l=\"abcn=a,b\", cn=c", "c");
+ assertCns("l=\"abcn=a,b\", cn=c", "c");
+ assertCns("l=\"abcn=a,b\", cn= c", "c");
+ assertCns("cn=<", "<");
+ assertCns("cn=>", ">");
+ assertCns("cn= >", ">");
+ assertCns("cn=a b", "a b");
+ assertCns("cn =a b", "a b");
+ assertCns("Cn=a b", "a b");
+ assertCns("cN=a b", "a b");
+ assertCns("CN=a b", "a b");
+ assertCns("cn=a#b", "a#b");
+ assertCns("cn=#130161", "a");
+ assertCns("l=q\t+cn=p", "p");
+ assertCns("l=q\n+cn=p", "p");
+ assertCns("l=q\n,cn=p", "p");
+ assertCns("l=,cn=p", "p");
+ assertCns("l=\tq\n,cn=\tp", "\tp");
+ }
+
+ /** A cn=, generates an empty value, unless it's at the very end */
+ public void testEmptyValues() {
+ assertCns("l=,cn=+cn=q", "", "q");
+ assertCns("l=,cn=,cn=q", "", "q");
+ assertCns("l=,cn=");
+ assertCns("l=,cn=q,cn= ", "q");
+ assertCns("l=,cn=q ,cn= ", "q");
+ assertCns("l=,cn=\"\"");
+ assertCns("l=,cn=\" \",cn=\" \"", " ", " ");
+ assertCns("l=,cn= ,cn= ","");
+ assertCns("l=,cn=,cn= ,cn= ", "", "");
+ }
+
+
+ public void testGetCns_escapedChars() {
+ assertCns("cn=\\,", ",");
+ assertCns("cn=\\#", "#");
+ assertCns("cn=\\+", "+");
+ assertCns("cn=\\\"", "\"");
+ assertCns("cn=\\\\", "\\");
+ assertCns("cn=\\<", "<");
+ assertCns("cn=\\>", ">");
+ assertCns("cn=\\;", ";");
+ assertCns("cn=\\+", "+");
+ assertCns("cn=\"\\+\"", "+");
+ assertCns("cn=\"\\,\"", ",");
+ assertCns("cn= a =", "a =");
+ assertCns("cn==", "=");
+ }
+
+ public void testGetCns_whitespace() {
+ assertCns("cn= p", "p");
+ assertCns("cn=\np", "p");
+ assertCns("cn=\tp", "p");
+ }
+
+ public void testGetCnsWithOid() {
+ assertCns("2.5.4.3=a,ou=xxx", "a");
+ assertCns("2.5.4.3=\" a \",ou=xxx", " a ");
+ assertCns("2.5.5.3=a,ou=xxx,cn=b", "b");
+ }
+
+ public void testGetCnsWithQuotedStrings() {
+ assertCns("cn=\"\\\" a ,=<>#;\"", "\" a ,=<>#;");
+ assertCns("cn=abc\\,def", "abc,def");
+ assertCns("cn=\"\\\" a ,\\=<>\\#;\"", "\" a ,=<>#;");
+ }
+
+ public void testGetCnsWithUtf8() {
+ assertCns("cn=\"Lu\\C4\\8Di\\C4\\87\"", "\u004c\u0075\u010d\u0069\u0107");
+ assertCns("cn=Lu\\C4\\8Di\\C4\\87", "\u004c\u0075\u010d\u0069\u0107");
+ assertCns("cn=Lu\\C4\\8di\\c4\\87", "\u004c\u0075\u010d\u0069\u0107");
+ assertCns("cn=\"Lu\\C4\\8di\\c4\\87\"", "\u004c\u0075\u010d\u0069\u0107");
+ assertCns("cn=\u004c\u0075\u010d\u0069\u0107", "\u004c\u0075\u010d\u0069\u0107");
+ // \63=c
+ assertExceptionInPrincipal("\\63n=ab");
+ assertExceptionInPrincipal("cn=\\a");
+ }
+
+ public void testGetCnsWithWhitespace() {
+ assertCns("ou=a, cn= a b ,o=x", "a b");
+ assertCns("cn=\" a b \" ,o=x", " a b ");
+ }
+
+ private static void assertCns(String dn, String... expected) {
+ String[] result = AbstractVerifier.getCNs(createStubCertificate(dn));
+ if (expected.length == 0) {
+ assertNull(result);
+ } else {
+ assertNotNull(dn, result);
+ assertEquals(dn, Arrays.asList(expected), Arrays.asList(result));
+ }
+ }
+
+ private static void assertExceptionInPrincipal(String dn) {
+ try {
+ X500Principal principal = new X500Principal(dn);
+ fail("Expected " + IllegalArgumentException.class.getName()
+ + " because of incorrect input name");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ private static X509Certificate createStubCertificate(final String subjectName) {
+ return new X509Certificate() {
+ @Override
+ public X500Principal getSubjectX500Principal() {
+ return new X500Principal(subjectName);
+ }
+
+ @Override
+ public Set<String> getCriticalExtensionOIDs() {
+ return null;
+ }
+
+ @Override
+ public byte[] getExtensionValue(String oid) {
+ return new byte[0];
+ }
+
+ @Override
+ public Set<String> getNonCriticalExtensionOIDs() {
+ return null;
+ }
+
+ @Override
+ public boolean hasUnsupportedCriticalExtension() {
+ return false;
+ }
+
+ @Override
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return new byte[0];
+ }
+
+ @Override
+ public void verify(PublicKey key)
+ throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+
+ }
+
+ @Override
+ public void verify(PublicKey key, String sigProvider)
+ throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+
+ }
+
+ @Override
+ public String toString() {
+ return null;
+ }
+
+ @Override
+ public PublicKey getPublicKey() {
+ return null;
+ }
+
+ @Override
+ public void checkValidity()
+ throws CertificateExpiredException, CertificateNotYetValidException {
+
+ }
+
+ @Override
+ public void checkValidity(Date date)
+ throws CertificateExpiredException, CertificateNotYetValidException {
+
+ }
+
+ @Override
+ public int getVersion() {
+ return 0;
+ }
+
+ @Override
+ public BigInteger getSerialNumber() {
+ return null;
+ }
+
+ @Override
+ public Principal getIssuerDN() {
+ return null;
+ }
+
+ @Override
+ public Principal getSubjectDN() {
+ return null;
+ }
+
+ @Override
+ public Date getNotBefore() {
+ return null;
+ }
+
+ @Override
+ public Date getNotAfter() {
+ return null;
+ }
+
+ @Override
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+ return new byte[0];
+ }
+
+ @Override
+ public byte[] getSignature() {
+ return new byte[0];
+ }
+
+ @Override
+ public String getSigAlgName() {
+ return null;
+ }
+
+ @Override
+ public String getSigAlgOID() {
+ return null;
+ }
+
+ @Override
+ public byte[] getSigAlgParams() {
+ return new byte[0];
+ }
+
+ @Override
+ public boolean[] getIssuerUniqueID() {
+ return new boolean[0];
+ }
+
+ @Override
+ public boolean[] getSubjectUniqueID() {
+ return new boolean[0];
+ }
+
+ @Override
+ public boolean[] getKeyUsage() {
+ return new boolean[0];
+ }
+
+ @Override
+ public int getBasicConstraints() {
+ return 0;
+ }
+ };
+ }
+}
+
diff --git a/tests/tests/openglperf/Android.mk b/tests/tests/openglperf/Android.mk
index 6b42ed0..9d2d184 100644
--- a/tests/tests/openglperf/Android.mk
+++ b/tests/tests/openglperf/Android.mk
@@ -26,7 +26,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ctsdeviceutil
-LOCAL_JNI_SHARED_LIBRARIES := libctsopenglperf_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctsopenglperf_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/openglperf/jni/Android.mk b/tests/tests/openglperf/jni/Android.mk
index 2cebaec..d6df59b2 100644
--- a/tests/tests/openglperf/jni/Android.mk
+++ b/tests/tests/openglperf/jni/Android.mk
@@ -24,7 +24,7 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(call include-path-for, system-core) frameworks/native/opengl/include
-LOCAL_SHARED_LIBRARIES := libnativehelper libcutils liblog libGLES_trace libEGL
+LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog libEGL
LOCAL_SDK_VERSION := 14
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index f4b140e..3326fb1 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -26,7 +26,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner guava
-LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libctsos_jni
+LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libctsos_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/android/os/cts/IParcelFileDescriptorPeer.aidl \
diff --git a/tests/tests/os/jni/Android.mk b/tests/tests/os/jni/Android.mk
index c125f5c..6d2f1dd 100644
--- a/tests/tests/os/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -62,10 +62,11 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog libdl libcutils
+LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog libdl
+LOCAL_CXX_STL := none
LOCAL_SRC_FILES += android_os_cts_CpuFeatures.cpp
LOCAL_C_INCLUDES += ndk/sources/cpufeatures
-LOCAL_STATIC_LIBRARIES := cpufeatures
+LOCAL_STATIC_LIBRARIES := cpufeatures libc++_static
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/os/jni/android_os_cts_HardwareName.cpp b/tests/tests/os/jni/android_os_cts_HardwareName.cpp
index 6752aa3..74b630e 100644
--- a/tests/tests/os/jni/android_os_cts_HardwareName.cpp
+++ b/tests/tests/os/jni/android_os_cts_HardwareName.cpp
@@ -16,15 +16,13 @@
*/
#include <jni.h>
-#include <cutils/properties.h>
+#include <sys/system_properties.h>
jstring android_os_cts_HardwareName_getName(JNIEnv* env, jobject thiz)
{
- char name[PROPERTY_VALUE_MAX];
- int ret;
+ char name[PROP_VALUE_MAX];
- ret = property_get("ro.boot.hardware", name, NULL);
- if (ret <= 0) {
+ if (__system_property_get("ro.boot.hardware", name) <= 0) {
return NULL;
}
diff --git a/tests/tests/os/src/android/os/cts/BundleTest.java b/tests/tests/os/src/android/os/cts/BundleTest.java
index 0db5fd0..36326b3 100644
--- a/tests/tests/os/src/android/os/cts/BundleTest.java
+++ b/tests/tests/os/src/android/os/cts/BundleTest.java
@@ -730,6 +730,26 @@
assertTrue(mBundle.hasFileDescriptors());
}
+ public void testHasFileDescriptorsOnNullValuedCollection() {
+ assertFalse(mBundle.hasFileDescriptors());
+
+ mBundle.putParcelableArray("foo", new Parcelable[1]);
+ assertFalse(mBundle.hasFileDescriptors());
+ mBundle.clear();
+
+ SparseArray<Parcelable> sparseArray = new SparseArray<Parcelable>();
+ sparseArray.put(0, null);
+ mBundle.putSparseParcelableArray("bar", sparseArray);
+ assertFalse(mBundle.hasFileDescriptors());
+ mBundle.clear();
+
+ ArrayList<Parcelable> arrayList = new ArrayList<Parcelable>();
+ arrayList.add(null);
+ mBundle.putParcelableArrayList("baz", arrayList);
+ assertFalse(mBundle.hasFileDescriptors());
+ mBundle.clear();
+ }
+
public void testSetClassLoader() {
mBundle.setClassLoader(new MockClassLoader());
}
diff --git a/tests/tests/permission/Android.mk b/tests/tests/permission/Android.mk
index 6a7da5f..49cec4d 100644
--- a/tests/tests/permission/Android.mk
+++ b/tests/tests/permission/Android.mk
@@ -26,7 +26,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner guava android-ex-camera2
-LOCAL_JNI_SHARED_LIBRARIES := libctspermission_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctspermission_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/permission/jni/Android.mk b/tests/tests/permission/jni/Android.mk
index 44e742e..ea45096 100644
--- a/tests/tests/permission/jni/Android.mk
+++ b/tests/tests/permission/jni/Android.mk
@@ -27,6 +27,7 @@
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog
+LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog
+LOCAL_SDK_VERSION := 23
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp b/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
index 8f32027..0547be4 100644
--- a/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
+++ b/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
+#include <android/log.h>
#include <jni.h>
#include <stdio.h>
-#include <cutils/log.h>
#include <linux/xattr.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -104,7 +104,8 @@
sizeof(capData));
if (result <= 0)
{
- ALOGD("isPermittedCapBitSet(): getxattr(\"%s\") call failed: "
+ __android_log_print(ANDROID_LOG_DEBUG, NULL,
+ "isPermittedCapBitSet(): getxattr(\"%s\") call failed: "
"return %d (error: %s (%d))\n",
cPath.c_str(), result, strerror(errno), errno);
return false;
@@ -132,7 +133,8 @@
ScopedLocalRef<jclass> eClazz(env, env->FindClass(className));
if (eClazz.get() == NULL)
{
- ALOGE("throwNamedException(): failed to find class %s, cannot throw",
+ __android_log_print(ANDROID_LOG_ERROR, NULL,
+ "throwNamedException(): failed to find class %s, cannot throw",
className);
return false;
}
@@ -186,7 +188,8 @@
sizeof(actualCapData));
if (result <= 0)
{
- ALOGD("fileHasOnly(): getxattr(\"%s\") call failed: "
+ __android_log_print(ANDROID_LOG_DEBUG, NULL,
+ "fileHasOnly(): getxattr(\"%s\") call failed: "
"return %d (error: %s (%d))\n",
cPath.c_str(), result, strerror(errno), errno);
return false;
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 7ef725b..d5c5279 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -19,7 +19,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Environment;
-import android.os.SystemProperties;
import android.system.Os;
import android.system.OsConstants;
import android.system.StructStatVfs;
@@ -109,7 +108,7 @@
String myAppDirectory = getContext().getApplicationInfo().dataDir;
for (ApplicationInfo app : apps) {
if (!myAppDirectory.equals(app.dataDir)) {
- writableDirs.addAll(getWritableDirectoryiesAndSubdirectoriesOf(new File(app.dataDir)));
+ writableDirs.addAll(getWritableDirectoriesAndSubdirectoriesOf(new File(app.dataDir)));
}
}
@@ -360,7 +359,6 @@
@MediumTest
public void testDeviceTreeCpuCurrent() throws Exception {
String arch = System.getProperty("os.arch");
- String flavor = SystemProperties.get("ro.build.flavor");
String[] osVersion = System.getProperty("os.version").split("\\.");
/*
* Perform the test for only arm-based architecture and
@@ -418,7 +416,7 @@
@LargeTest
public void testAllOtherDirectoriesNotWritable() throws Exception {
File start = new File("/");
- Set<File> writableDirs = getWritableDirectoryiesAndSubdirectoriesOf(start);
+ Set<File> writableDirs = getWritableDirectoriesAndSubdirectoriesOf(start);
assertTrue("Found writable directories: " + writableDirs.toString(),
writableDirs.isEmpty());
@@ -609,7 +607,7 @@
Set<File> writableDirs = new HashSet<File>();
for (String dir : OTHER_RANDOM_DIRECTORIES) {
File start = new File(dir);
- writableDirs.addAll(getWritableDirectoryiesAndSubdirectoriesOf(start));
+ writableDirs.addAll(getWritableDirectoriesAndSubdirectoriesOf(start));
}
assertTrue("Found writable directories: " + writableDirs.toString(),
@@ -1030,7 +1028,7 @@
return retval;
}
- private Set<File> getWritableDirectoryiesAndSubdirectoriesOf(File dir) throws Exception {
+ private Set<File> getWritableDirectoriesAndSubdirectoriesOf(File dir) throws Exception {
Set<File> retval = new HashSet<File>();
if (!dir.isDirectory()) {
return retval;
@@ -1059,7 +1057,7 @@
}
for (File f : subFiles) {
- retval.addAll(getWritableDirectoryiesAndSubdirectoriesOf(f));
+ retval.addAll(getWritableDirectoriesAndSubdirectoriesOf(f));
}
return retval;
diff --git a/tests/tests/provider/Android.mk b/tests/tests/provider/Android.mk
index 58a7516..5064d4b 100644
--- a/tests/tests/provider/Android.mk
+++ b/tests/tests/provider/Android.mk
@@ -29,7 +29,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner
-LOCAL_JNI_SHARED_LIBRARIES := libcts_jni
+LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/renderscript/Android.mk b/tests/tests/renderscript/Android.mk
index 7b30859..5266e34 100644
--- a/tests/tests/renderscript/Android.mk
+++ b/tests/tests/renderscript/Android.mk
@@ -28,8 +28,8 @@
# When built, explicitly put it in the data partition.
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
-LOCAL_JNI_SHARED_LIBRARIES := libcoremathtestcpp_jni libbnnmdata_jni
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner xmp_toolkit
+LOCAL_JNI_SHARED_LIBRARIES := libcoremathtestcpp_jni
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
diff --git a/tests/tests/renderscript/AndroidManifest.xml b/tests/tests/renderscript/AndroidManifest.xml
index b9405ca..6e67f9e 100644
--- a/tests/tests/renderscript/AndroidManifest.xml
+++ b/tests/tests/renderscript/AndroidManifest.xml
@@ -22,6 +22,8 @@
package="com.android.cts.renderscript">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application>
<uses-library android:name="android.test.runner" />
</application>
diff --git a/tests/tests/renderscript/libcoremathtestcpp/Android.mk b/tests/tests/renderscript/libcoremathtestcpp/Android.mk
index 3b693e0..c62f20e 100644
--- a/tests/tests/renderscript/libcoremathtestcpp/Android.mk
+++ b/tests/tests/renderscript/libcoremathtestcpp/Android.mk
@@ -24,10 +24,13 @@
LOCAL_CFLAGS := -std=c++11
+LOCAL_SDK_VERSION := 21
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
-LOCAL_SHARED_LIBRARIES := libdl liblog libRScpp
-LOCAL_STATIC_LIBRARIES := libcutils
+LOCAL_LDFLAGS := -llog -ldl
+LOCAL_STATIC_LIBRARIES := libRScpp_static libcutils
include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/renderscript/res/drawable-nodpi/refocus_image.jpg b/tests/tests/renderscript/res/drawable-nodpi/refocus_image.jpg
new file mode 100755
index 0000000..347c3f9
--- /dev/null
+++ b/tests/tests/renderscript/res/drawable-nodpi/refocus_image.jpg
Binary files differ
diff --git a/tests/tests/renderscript/res/drawable-nodpi/refocus_reference.png b/tests/tests/renderscript/res/drawable-nodpi/refocus_reference.png
new file mode 100644
index 0000000..7d077ef
--- /dev/null
+++ b/tests/tests/renderscript/res/drawable-nodpi/refocus_reference.png
Binary files differ
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
index 7e867f7..9e42a6c 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
@@ -779,6 +779,47 @@
assertTrue(result[0] == 2);
}
+ public void testDimReturnsZero() {
+ Allocation a;
+ a = Allocation.createSized(mRS, Element.F32(mRS), 100);
+ assertTrue(a.getType().getX() == 100);
+ assertTrue(a.getType().getY() == 0);
+ assertTrue(a.getType().getZ() == 0);
+ a.destroy();
+
+ Type.Builder b;
+ b = new Type.Builder(mRS, Element.F32(mRS));
+ a = Allocation.createTyped(mRS, b.create());
+
+ assertTrue(a.getType().getX() == 1);
+ assertTrue(a.getType().getY() == 0);
+ assertTrue(a.getType().getZ() == 0);
+
+ a.destroy();
+
+ b = new Type.Builder(mRS, Element.F32(mRS)).setX(102);
+ a = Allocation.createTyped(mRS, b.create());
+
+ assertTrue(a.getType().getX() == 102);
+ assertTrue(a.getType().getY() == 0);
+ assertTrue(a.getType().getZ() == 0);
+ a.destroy();
+ b = new Type.Builder(mRS, Element.F32(mRS)).setX(102).setY(123);
+ a = Allocation.createTyped(mRS, b.create());
+
+ assertTrue(a.getType().getX() == 102);
+ assertTrue(a.getType().getY() == 123);
+ assertTrue(a.getType().getZ() == 0);
+ a.destroy();
+ b = new Type.Builder(mRS, Element.F32(mRS)).setX(2).setY(33).setZ(23);
+ a = Allocation.createTyped(mRS, b.create());
+
+ assertTrue(a.getType().getX() == 2);
+ assertTrue(a.getType().getY() == 33);
+ assertTrue(a.getType().getZ() == 23);
+
+ a.destroy();
+ }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ImageProcessingTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ImageProcessingTest.java
index f38bdb0..df8a6fe 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ImageProcessingTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ImageProcessingTest.java
@@ -47,6 +47,7 @@
import android.renderscript.Short4;
import android.renderscript.Matrix4f;
+import android.renderscript.Script;
import android.renderscript.Type;
@@ -58,6 +59,7 @@
import android.renderscript.ScriptIntrinsicConvolve3x3;
import android.renderscript.ScriptIntrinsicConvolve5x5;
import android.renderscript.ScriptIntrinsicLUT;
+import android.util.Log;
public class ImageProcessingTest extends RSBaseCompute {
private Allocation a1, a2;
@@ -100,67 +102,551 @@
public void testBlend() {
ScriptIntrinsicBlend mBlend;
mBlend = ScriptIntrinsicBlend.create(mRS, Element.U8_4(mRS));
-
- Allocation a1_copy, a2_copy;
- a1_copy = Allocation.createTyped(mRS, a1.getType());
- a2_copy = Allocation.createTyped(mRS, a2.getType());
-
- for (int i = 0; i < 14; i++) {
-
- a1_copy.copy2DRangeFrom(0, 0, a1.getType().getX(), a1.getType().getY(), a1, 0, 0);
- a2_copy.copy2DRangeFrom(0, 0, a2.getType().getX(), a2.getType().getY(), a2, 0, 0);
+ int w = 256;
+ int h = 256;
+ Allocation src = creatAllocation(w, h);
+ Allocation dst = creatAllocation(w, h);
+ byte[] srcData = new byte[w * h * 4];
+ byte[] dstData = new byte[w * h * 4];
+ byte[] resultData = new byte[w * h * 4];
+ Script.LaunchOptions opt = new Script.LaunchOptions();
+ // unclipped but with options
+ for (int i = 0; i < 28; i++) {
+ buildSrc(srcData, w, h);
+ buildDst(dstData, w, h);
+ src.copyFromUnchecked(srcData);
+ dst.copyFromUnchecked(dstData);
switch (i) {
- case 0:
- mBlend.forEachSrc(a1_copy, a2_copy);
- break;
- case 1:
- mBlend.forEachDst(a1_copy, a2_copy);
- break;
- case 2:
- mBlend.forEachSrcOver(a1_copy, a2_copy);
- break;
- case 3:
- mBlend.forEachDstOver(a1_copy, a2_copy);
- break;
- case 4:
- mBlend.forEachSrcIn(a1_copy, a2_copy);
- break;
- case 5:
- mBlend.forEachDstIn(a1_copy, a2_copy);
- break;
- case 6:
- mBlend.forEachSrcOut(a1_copy, a2_copy);
- break;
- case 7:
- mBlend.forEachDstOut(a1_copy, a2_copy);
- break;
- case 8:
- mBlend.forEachSrcAtop(a1_copy, a2_copy);
- break;
- case 9:
- mBlend.forEachDstAtop(a1_copy, a2_copy);
- break;
- case 10:
- mBlend.forEachXor(a1_copy, a2_copy);
- break;
- case 11:
- mBlend.forEachAdd(a1_copy, a2_copy);
- break;
- case 12:
- mBlend.forEachSubtract(a1_copy, a2_copy);
- break;
- case 13:
- mBlend.forEachMultiply(a1_copy, a2_copy);
- break;
+ case 0:
+ mBlend.forEachSrc(src, dst);
+ break;
+ case 1:
+ mBlend.forEachDst(src, dst);
+ break;
+ case 2:
+ mBlend.forEachSrcOver(src, dst);
+ break;
+ case 3:
+ mBlend.forEachDstOver(src, dst);
+ break;
+ case 4:
+ mBlend.forEachSrcIn(src, dst);
+ break;
+ case 5:
+ mBlend.forEachDstIn(src, dst);
+ break;
+ case 6:
+ mBlend.forEachSrcOut(src, dst);
+ break;
+ case 7:
+ mBlend.forEachDstOut(src, dst);
+ break;
+ case 8:
+ mBlend.forEachSrcAtop(src, dst);
+ break;
+ case 9:
+ mBlend.forEachDstAtop(src, dst);
+ break;
+ case 10:
+ mBlend.forEachXor(src, dst);
+ break;
+ case 11:
+ mBlend.forEachAdd(src, dst);
+ break;
+ case 12:
+ mBlend.forEachSubtract(src, dst);
+ break;
+ case 13:
+ mBlend.forEachMultiply(src, dst);
+ break;
+ case 14:
+ mBlend.forEachSrc(src, dst, opt);
+ break;
+ case 15:
+ mBlend.forEachDst(src, dst, opt);
+ break;
+ case 16:
+ mBlend.forEachSrcOver(src, dst, opt);
+ break;
+ case 17:
+ mBlend.forEachDstOver(src, dst, opt);
+ break;
+ case 18:
+ mBlend.forEachSrcIn(src, dst, opt);
+ break;
+ case 19:
+ mBlend.forEachDstIn(src, dst, opt);
+ break;
+ case 20:
+ mBlend.forEachSrcOut(src, dst, opt);
+ break;
+ case 21:
+ mBlend.forEachDstOut(src, dst, opt);
+ break;
+ case 22:
+ mBlend.forEachSrcAtop(src, dst, opt);
+ break;
+ case 23:
+ mBlend.forEachDstAtop(src, dst, opt);
+ break;
+ case 24:
+ mBlend.forEachXor(src, dst, opt);
+ break;
+ case 25:
+ mBlend.forEachAdd(src, dst, opt);
+ break;
+ case 26:
+ mBlend.forEachSubtract(src, dst, opt);
+ break;
+ case 27:
+ mBlend.forEachMultiply(src, dst, opt);
+ break;
}
+ dst.copyTo(resultData);
+ String name = javaBlend(i%14, srcData, dstData);
+ assertTrue(name, similar(resultData,dstData));
+ Log.v("BlendUnit", name + " " + similar(resultData, dstData));
- // validate
+ }
+ }
+ // utility to create and allocation of a given dimension
+ protected Allocation creatAllocation(int w, int h) {
+ Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
+ b.setX(w);
+ b.setY(h);
+ return Allocation.createTyped(mRS, b.create(), Allocation.USAGE_SCRIPT);
+ }
+
+ // Compare two images ensuring returning false if error is greater than 2
+ // so that it can support integer and float non identical versions
+ public boolean similar(byte[] a, byte[] b) {
+ for (int i = 0; i < a.length; i++) {
+ int v1 = 0xFF & a[i];
+ int v2 = 0xFF & b[i];
+ int error = Math.abs(v1 - v2);
+ if (error > 2) {
+ return false;
+ }
+ }
+ return true;
+ }
+ // Build a test pattern to be the source pattern designed to provide a wide range of values
+ public void buildSrc(byte[] srcData, int width, int height) {
+ for (int i = 0; i < srcData.length / 4; i++) {
+ int x = i % width;
+ int y = i / width;
+ int d = (x - width / 2) * (x - width / 2) + (y - height / 2) * (y - height / 2);
+ d = (255 * d) / ((width / 2) * (width / 2));
+ d = (d > 255) ? 0 : d;
+
+ srcData[i * 4 + 0] = (byte) d; // red
+ srcData[i * 4 + 1] = (byte) d; // green
+ srcData[i * 4 + 2] = (byte) 0; // blue
+ srcData[i * 4 + 3] = (byte) y; // alpha
+ }
+ }
+
+ // Build a test pattern to be the destination pattern designed to provide a wide range of values
+ public void buildDst(byte[] dstData, int width, int height) {
+ for (int i = 0; i < dstData.length / 4; i++) {
+ int x = i % width;
+ int y = i / width;
+
+ dstData[i * 4 + 0] = (byte) 0; // red
+ dstData[i * 4 + 1] = (byte) 0; // green
+ dstData[i * 4 + 2] = (byte) y; // blue
+ dstData[i * 4 + 3] = (byte) x; // alpha
}
}
+ public String javaBlend(int type, byte[] src, byte[] dst) {
+
+ for (int i = 0; i < dst.length; i += 4) {
+ byte[] rgba = func[type].filter(src[i], src[i + 1], src[i + 2], src[i + 3],
+ dst[i], dst[i + 1], dst[i + 2], dst[i + 3]);
+ dst[i] = rgba[0];
+ dst[i + 1] = rgba[1];
+ dst[i + 2] = rgba[2];
+ dst[i + 3] = rgba[3];
+ }
+ return func[type].name;
+ }
+
+ // Base class for Java blend implementation supporting float and int implementations
+
+ abstract class BlendFunc {
+ float srcR, srcG, srcB, srcA;
+ float dstR, dstG, dstB, dstA;
+ int s_srcR, s_srcG, s_srcB, s_srcA;
+ int s_dstR, s_dstG, s_dstB, s_dstA;
+ byte[] rgba = new byte[4];
+ String name;
+
+ final int clamp(int c) {
+ final int N = 255;
+ c &= ~(c >> 31);
+ c -= N;
+ c &= (c >> 31);
+ c += N;
+ return c;
+ }
+
+ int pack(float a, float r, float g, float b) {
+ int ia = clamp((int) (255 * a));
+ int ir = clamp((int) (255 * r));
+ int ig = clamp((int) (255 * g));
+ int ib = clamp((int) (255 * b));
+ rgba[0] = (byte) ir;
+ rgba[1] = (byte) ig;
+ rgba[2] = (byte) ib;
+ rgba[3] = (byte) ia;
+ return (ia << 24) | (ir << 16) | (ig << 8) | ib;
+ }
+
+ int pack(int a, int r, int g, int b) {
+
+ rgba[0] = (byte) clamp(r);
+ rgba[1] = (byte) clamp(g);
+ rgba[2] = (byte) clamp(b);
+ rgba[3] = (byte) clamp(a);
+ return 0;
+ }
+
+ void unpackSrc(int src) {
+ s_srcR = (0xFF & (src >> 16));
+ s_srcG = (0xFF & (src >> 8));
+ s_srcB = (0xFF & (src >> 0));
+ s_srcA = (0xFF & (src >> 24));
+ float scale = 1 / 255f;
+
+ srcR = (0xFF & (src >> 16)) * scale;
+ srcG = (0xFF & (src >> 8)) * scale;
+ srcB = (0xFF & (src >> 0)) * scale;
+ srcA = (0xFF & (src >> 24)) * scale;
+ }
+
+ void unpackDst(int dst) {
+ float scale = 1 / 255f;
+
+ s_dstR = (0xFF & (dst >> 16));
+ s_dstG = (0xFF & (dst >> 8));
+ s_dstB = (0xFF & (dst >> 0));
+ s_dstA = (0xFF & (dst >> 24));
+
+ dstR = (0xFF & (dst >> 16)) * scale;
+ dstG = (0xFF & (dst >> 8)) * scale;
+ dstB = (0xFF & (dst >> 0)) * scale;
+ dstA = (0xFF & (dst >> 24)) * scale;
+ }
+
+ int filter(int scr, int dst) {
+ unpackSrc(scr);
+ unpackDst(dst);
+ return blend();
+ }
+
+ byte[] filter(byte srcR, byte srcG, byte srcB, byte srcA,
+ byte dstR, byte dstG, byte dstB, byte dstA) {
+ float scale = 1 / 255f;
+ this.srcR = (0xFF & (srcR)) * scale;
+ this.srcG = (0xFF & (srcG)) * scale;
+ this.srcB = (0xFF & (srcB)) * scale;
+ this.srcA = (0xFF & (srcA)) * scale;
+
+ this.dstR = (0xFF & (dstR)) * scale;
+ this.dstG = (0xFF & (dstG)) * scale;
+ this.dstB = (0xFF & (dstB)) * scale;
+ this.dstA = (0xFF & (dstA)) * scale;
+ s_dstR = (0xFF & (dstR));
+ s_dstG = (0xFF & (dstG));
+ s_dstB = (0xFF & (dstB));
+ s_dstA = (0xFF & (dstA));
+
+ s_srcR = (0xFF & (srcR));
+ s_srcG = (0xFF & (srcG));
+ s_srcB = (0xFF & (srcB));
+ s_srcA = (0xFF & (srcA));
+
+ blend();
+ return rgba;
+ }
+
+ abstract int blend();
+ }
+
+ BlendFunc blend_dstAtop = new BlendFunc() {
+ // dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
+ // dst.a = src.a
+ {
+ name = "blend_dstAtop";
+ }
+
+ @Override
+ int blend() {
+ float r = (dstR * srcA + (1 - dstA) * srcR);
+ float g = (dstG * srcA + (1 - dstA) * srcG);
+ float b = (dstB * srcA + (1 - dstA) * srcB);
+ float a = srcA;
+
+ return pack(a, r, g, b);
+ }
+ };
+ BlendFunc blend_dstIn = new BlendFunc() {
+ // Sets dst = dst * src.a
+ {
+ name = "blend_dstIn";
+ }
+
+ @Override
+ int blend() {
+ float r = (dstR * srcA);
+ float g = (dstG * srcA);
+ float b = (dstB * srcA);
+ float a = (dstA * srcA);
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_add = new BlendFunc() {
+ // dst = dst + src
+ {
+ name = "blend_add";
+ }
+
+ @Override
+ int blend() {
+
+ int r = Math.min(s_dstR + s_srcR, 255);
+ int g = Math.min(s_dstG + s_srcG, 255);
+ int b = Math.min(s_dstB + s_srcB, 255);
+ int a = Math.min(s_dstA + s_srcA, 255);
+ return pack(a, r, g, b);
+
+ }
+ };
+
+ BlendFunc blend_clear = new BlendFunc() {
+ // Sets dst = {0, 0, 0, 0}
+ {
+ name = "blend_clear";
+ }
+
+ @Override
+ int blend() {
+ return pack(0, 0, 0, 0);
+ }
+ };
+
+ BlendFunc blend_dst = new BlendFunc() {
+ // Sets dst = dst
+ {
+ name = "blend_dst";
+ }
+
+ @Override
+ int blend() {
+ return pack(dstA, dstR, dstG, dstB);
+ }
+ };
+
+ BlendFunc blend_dstOut = new BlendFunc() {
+ // Sets dst = dst * (1.0 - src.a)
+ {
+ name = "blend_dstOut";
+ }
+
+ @Override
+ int blend() {
+ float r = (dstR * (1 - srcA));
+ float g = (dstG * (1 - srcA));
+ float b = (dstB * (1 - srcA));
+ float a = (dstA * (1 - srcA));
+ return pack(a, r, g, b);
+ }
+ };
+ BlendFunc blend_dstOver = new BlendFunc() {
+ // Sets dst = dst + src * (1.0 - dst.a)
+ {
+ name = "blend_dstOver";
+ }
+
+ @Override
+ int blend() {
+ float r = dstR + (srcR * (1 - dstA));
+ float g = dstG + (srcG * (1 - dstA));
+ float b = dstB + (srcB * (1 - dstA));
+ float a = dstA + (srcA * (1 - dstA));
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_multiply = new BlendFunc() {
+ // dst = dst * src
+ {
+ name = "blend_multiply";
+ }
+
+ @Override
+ int blend() {
+ float r = (srcR * dstR);
+ float g = (srcG * dstG);
+ float b = (srcB * dstB);
+ float a = (srcA * dstA);
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_src = new BlendFunc() {
+ // Sets dst = src
+ {
+ name = "blend_src";
+ }
+
+ int blend() {
+ return pack(srcA, srcR, srcG, srcB);
+
+ }
+ };
+
+ BlendFunc blend_srcAtop = new BlendFunc() {
+ // dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
+ // dst.a = dst.a
+ {
+ name = "blend_srcAtop";
+ }
+
+ @Override
+ int blend() {
+ float r = (srcR * dstA + (1 - srcA) * dstR);
+ float g = (srcG * dstA + (1 - srcA) * dstG);
+ float b = (srcB * dstA + (1 - srcA) * dstB);
+ float a = (srcA * dstA + (1 - srcA) * dstA);
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_srcIn = new BlendFunc() {
+ // dst = src * dst.a
+ {
+ name = "blend_srcIn";
+ }
+
+ @Override
+ int blend() {
+ float r = (srcR * dstA);
+ float g = (srcG * dstA);
+ float b = (srcB * dstA);
+ float a = (srcA * dstA);
+ ;
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_srcOut = new BlendFunc() {
+ // Sets dst = src * (1.0 - dst.a)
+ {
+ name = "blend_srcOut";
+ }
+
+ @Override
+ int blend() {
+ float r = (srcR * (1 - dstA));
+ float g = (srcG * (1 - dstA));
+ float b = (srcB * (1 - dstA));
+ float a = (srcA * (1 - dstA));
+ ;
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_srcOver = new BlendFunc() {
+ // Sets dst = src + dst * (1.0 - src.a)
+ {
+ name = "blend_srcOver";
+ }
+
+ @Override
+ int blend() {
+ float r = srcR + (dstR * (1 - srcA));
+ float g = srcG + (dstG * (1 - srcA));
+ float b = srcB + (dstB * (1 - srcA));
+ float a = srcA + (dstA * (1 - srcA));
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc blend_subtract = new BlendFunc() {
+ // Sets dst = dst - src
+ {
+ name = "blend_subtract";
+ }
+
+ @Override
+ int blend() {
+ float r = Math.max(dstR - srcR, 0);
+ float g = Math.max(dstG - srcG, 0);
+ float b = Math.max(dstB - srcB, 0);
+ float a = Math.max(dstA - srcA, 0);
+ return pack(a, r, g, b);
+ }
+ };
+
+ // Porter/Duff xor compositing
+ BlendFunc blend_pdxor = new BlendFunc() {
+ // dst.rgb = src.rgb*(1-dst.a)+(1-src.a)*dst.rgb;
+ // dst.a = src.a+dst.a - 2*src.a*dst.a
+ {
+ name = "blend_pdxor";
+ }
+
+ @Override
+ int blend() {
+ float r = srcR * (1 - dstA) + (dstR * (1 - srcA));
+ float g = srcG * (1 - dstA) + (dstG * (1 - srcA));
+ float b = srcB * (1 - dstA) + (dstB * (1 - srcA));
+ float a = srcA + dstA - (2 * srcA * dstA);
+ return pack(a, r, g, b);
+ }
+ };
+
+ // NOT Porter/Duff xor compositing simple XOR
+ BlendFunc blend_xor = new BlendFunc() {
+ // Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
+ {
+ name = "blend_xor";
+ }
+
+ @Override
+ int blend() {
+ float scale = 1 / 255f;
+ float r = (((int) (dstR * 255)) ^ ((int) (srcR * 255))) * scale;
+ float g = (((int) (dstG * 255)) ^ ((int) (srcG * 255))) * scale;
+ float b = (((int) (dstB * 255)) ^ ((int) (srcB * 255))) * scale;
+ float a = (((int) (dstA * 255)) ^ ((int) (srcA * 255))) * scale;
+ return pack(a, r, g, b);
+ }
+ };
+
+ BlendFunc[] func = {
+ blend_src,
+ blend_dst,
+ blend_srcOver,
+ blend_dstOver,
+ blend_srcIn,
+ blend_dstIn,
+ blend_srcOut,
+ blend_dstOut,
+ blend_srcAtop,
+ blend_dstAtop,
+ blend_xor,
+ blend_add,
+ blend_subtract,
+ blend_multiply,
+ };
+
public void testColorMatrix() {
ScriptIntrinsicColorMatrix mColorMatrix;
mColorMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
@@ -198,7 +684,6 @@
}
-
public void testConvolve3x3() {
ScriptIntrinsicConvolve3x3 mConvolve3x3;
mConvolve3x3 = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
index c8b3640..9392db1 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
@@ -97,87 +97,87 @@
}
- public void test_U8_4_SCALE10_10_inSqure() {
+ public void test_U8_4_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
checkError();
}
- public void test_U8_3_SCALE10_10_inSqure() {
+ public void test_U8_3_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
checkError();
}
- public void test_U8_2_SCALE10_10_inSqure() {
+ public void test_U8_2_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
checkError();
}
- public void test_U8_1_SCALE10_10_inSqure() {
+ public void test_U8_1_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
checkError();
}
- public void test_U8_4_SCALE20_20_inSqure() {
+ public void test_U8_4_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
checkError();
}
- public void test_U8_3_SCALE20_20_inSqure() {
+ public void test_U8_3_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
checkError();
}
- public void test_U8_2_SCALE20_20_inSqure() {
+ public void test_U8_2_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
checkError();
}
- public void test_U8_1_SCALE20_20_inSqure() {
+ public void test_U8_1_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
checkError();
}
- public void test_U8_4_SCALE05_20_inSqure() {
+ public void test_U8_4_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
checkError();
}
- public void test_U8_3_SCALE05_20_inSqure() {
+ public void test_U8_3_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
checkError();
}
- public void test_U8_2_SCALE05_20_inSqure() {
+ public void test_U8_2_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
checkError();
}
- public void test_U8_1_SCALE05_20_inSqure() {
+ public void test_U8_1_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
checkError();
}
- public void test_U8_4_SCALE20_05_inSqure() {
+ public void test_U8_4_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
checkError();
}
- public void test_U8_3_SCALE20_05_inSqure() {
+ public void test_U8_3_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
checkError();
}
- public void test_U8_2_SCALE20_05_inSqure() {
+ public void test_U8_2_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
checkError();
}
- public void test_U8_1_SCALE20_05_inSqure() {
+ public void test_U8_1_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
checkError();
}
- public void test_U8_4_SCALE05_05_inSqure() {
+ public void test_U8_4_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
checkError();
}
- public void test_U8_3_SCALE05_05_inSqure() {
+ public void test_U8_3_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
checkError();
}
- public void test_U8_2_SCALE05_05_inSqure() {
+ public void test_U8_2_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
checkError();
}
- public void test_U8_1_SCALE05_05_inSqure() {
+ public void test_U8_1_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
checkError();
}
@@ -268,87 +268,87 @@
}
- public void test_F32_4_SCALE10_10_inSqure() {
+ public void test_F32_4_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
checkError();
}
- public void test_F32_3_SCALE10_10_inSqure() {
+ public void test_F32_3_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
checkError();
}
- public void test_F32_2_SCALE10_10_inSqure() {
+ public void test_F32_2_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
checkError();
}
- public void test_F32_1_SCALE10_10_inSqure() {
+ public void test_F32_1_SCALE10_10_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
checkError();
}
- public void test_F32_4_SCALE20_20_inSqure() {
+ public void test_F32_4_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
checkError();
}
- public void test_F32_3_SCALE20_20_inSqure() {
+ public void test_F32_3_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
checkError();
}
- public void test_F32_2_SCALE20_20_inSqure() {
+ public void test_F32_2_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
checkError();
}
- public void test_F32_1_SCALE20_20_inSqure() {
+ public void test_F32_1_SCALE20_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
checkError();
}
- public void test_F32_4_SCALE05_20_inSqure() {
+ public void test_F32_4_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
checkError();
}
- public void test_F32_3_SCALE05_20_inSqure() {
+ public void test_F32_3_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
checkError();
}
- public void test_F32_2_SCALE05_20_inSqure() {
+ public void test_F32_2_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
checkError();
}
- public void test_F32_1_SCALE05_20_inSqure() {
+ public void test_F32_1_SCALE05_20_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
checkError();
}
- public void test_F32_4_SCALE20_05_inSqure() {
+ public void test_F32_4_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
checkError();
}
- public void test_F32_3_SCALE20_05_inSqure() {
+ public void test_F32_3_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
checkError();
}
- public void test_F32_2_SCALE20_05_inSqure() {
+ public void test_F32_2_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
checkError();
}
- public void test_F32_1_SCALE20_05_inSqure() {
+ public void test_F32_1_SCALE20_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
checkError();
}
- public void test_F32_4_SCALE05_05_inSqure() {
+ public void test_F32_4_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
checkError();
}
- public void test_F32_3_SCALE05_05_inSqure() {
+ public void test_F32_3_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
checkError();
}
- public void test_F32_2_SCALE05_05_inSqure() {
+ public void test_F32_2_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
checkError();
}
- public void test_F32_1_SCALE05_05_inSqure() {
+ public void test_F32_1_SCALE05_05_inSquare() {
testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
checkError();
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SmallStructsTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SmallStructsTest.java
new file mode 100644
index 0000000..28a9528
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SmallStructsTest.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts;
+
+import android.renderscript.Allocation;
+import android.renderscript.Float4;
+import android.renderscript.RenderScript;
+
+import java.lang.reflect.Method;
+
+/*
+ * This checks that small structs (<= 64 bytes) are passed and
+ * returned correctly by forEach_* style kernels.
+ *
+ * There are three steps to each test: (a) setup, (b) modify, (c) verify.
+ * (a) the setup stage initializes the Allocation of structs
+ * (b) modify calls a forEach_* kernel with the Allocation
+ * (c) verify checks that the forEach_* kernel accessed the data as expected
+ */
+public class SmallStructsTest extends RSBaseCompute {
+ static final int sAllocationElements = 1024;
+ static final int sLargestCharArrayStructSize = 64;
+
+ static final String sTwoElementStructTypes[] =
+ {"i8", "i16", "i32", "i64", "f32", "f64", "v128"};
+
+ static final byte sInitialValue_int8_t = (byte) 0x7;
+ static final short sInitialValue_int16_t = (short) 0x1234;
+ static final int sInitialValue_int32_t = 0x12345678;
+ static final long sInitialValue_int64_t = 0x12345678abcdef1L;
+ static final float sInitialValue_float = 10473.f;
+ static final double sInitialValue_double = 35353143.25;
+ static final Float4 sInitialValue_float4 = new Float4(10473.f, 353541.5f, -5433.75f, 78394.f);
+
+ ScriptC_small_structs mScript;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mScript = new ScriptC_small_structs(mRS);
+ }
+
+ void checkForErrorsInScript() {
+ mRS.finish();
+ mScript.invoke_checkError();
+ waitForMessage();
+ checkForErrors();
+ }
+
+ /**
+ * Returns the class associated with the given type. For primitive types, the unwrapped class is
+ * returned.
+ */
+ Class<?> getUnwrappedClassForType(String type) {
+ if (type.equals("i8")) {
+ return byte.class;
+ } else if (type.equals("i16")) {
+ return short.class;
+ } else if (type.equals("i32")) {
+ return int.class;
+ } else if (type.equals("i64")) {
+ return long.class;
+ } else if (type.equals("f32")) {
+ return float.class;
+ } else if (type.equals("f64")) {
+ return double.class;
+ } else if (type.equals("v128")) {
+ return Float4.class;
+ } else {
+ fail("Unknown type tag: " + type);
+ return null;
+ }
+ }
+
+ /**
+ * Returns a ScriptC_small_structs setter associated with the global of the given type.
+ */
+ Method getInitialValueSetter(String type) throws Exception {
+ String name = "set_initial_value_";
+ if (type.equals("i8")) {
+ name += "int8_t";
+ } else if (type.equals("i16")) {
+ name += "int16_t";
+ } else if (type.equals("i32")) {
+ name += "int32_t";
+ } else if (type.equals("i64")) {
+ name += "int64_t";
+ } else if (type.equals("f32")) {
+ name += "float";
+ } else if (type.equals("f64")) {
+ name += "double";
+ } else if (type.equals("v128")) {
+ name += "float4";
+ } else {
+ fail("unknown type tag: " + type);
+ }
+
+ return ScriptC_small_structs.class.getMethod(name, getUnwrappedClassForType(type));
+ }
+
+ /**
+ * Returns the (possibly wrapped) initial value associated with the global of the given type.
+ */
+ Object getInitialValue(String type) {
+ if (type.equals("i8")) {
+ return (Object) sInitialValue_int8_t;
+ } else if (type.equals("i16")) {
+ return (Object) sInitialValue_int16_t;
+ } else if (type.equals("i32")) {
+ return (Object) sInitialValue_int32_t;
+ } else if (type.equals("i64")) {
+ return (Object) sInitialValue_int64_t;
+ } else if (type.equals("f32")) {
+ return (Object) sInitialValue_float;
+ } else if (type.equals("f64")) {
+ return (Object) sInitialValue_double;
+ } else if (type.equals("v128")) {
+ return (Object) sInitialValue_float4;
+ } else {
+ fail("unknown type tag: " + type);
+ return null;
+ }
+ }
+
+ /**
+ * Structs in this test are of the form
+ * struct char_array_N { char bytes[N]; };
+ */
+ public void testSmallStructsOfCharArray() throws Exception {
+ for (int size = 1; size <= sLargestCharArrayStructSize; ++size) {
+ // Make the input allocation.
+ Class<?> scriptFieldClass = Class.forName(
+ "android.renderscript.cts.ScriptField_char_array_" + size);
+
+ Object field = scriptFieldClass.getConstructor(RenderScript.class, int.class)
+ .newInstance(mRS, sAllocationElements);
+ Allocation alloc = (Allocation) scriptFieldClass.getMethod("getAllocation")
+ .invoke(field);
+
+ // void set_bytes(int index, byte[] bytes, boolean copyNow)
+ Method set_bytes = scriptFieldClass.getMethod("set_bytes",
+ int.class, byte[].class, boolean.class);
+
+ byte[] bytes = new byte[size];
+ for (int i = 0; i < size; ++i) {
+ bytes[i] = (byte) (1 + i);
+ }
+
+ for (int elem = 0; elem < sAllocationElements; ++elem) {
+ set_bytes.invoke(field, elem, bytes, true);
+ }
+
+ // Get methods used in testing.
+ Method modify = ScriptC_small_structs.class.getMethod(
+ "forEach_modify_char_array_" + size,
+ Allocation.class, Allocation.class);
+
+ Method verify = ScriptC_small_structs.class.getMethod(
+ "invoke_verify_char_array_" + size,
+ Allocation.class);
+
+ // Run the test.
+ modify.invoke(mScript, alloc, alloc);
+ verify.invoke(mScript, alloc);
+ }
+
+ checkForErrorsInScript();
+
+ // Check that all tests were run.
+ mScript.invoke_checkNumberOfCharArrayTestsRun();
+ waitForMessage();
+ checkForErrors();
+ }
+
+ /**
+ * Structs in this test are of the form
+ * struct two_element_struct_X { TYPE1 a; TYPE2 b };
+ */
+ public void testSmallStructsOfHeterogeneousTypes() throws Exception {
+ // Initialize script globals.
+ for (String type: sTwoElementStructTypes) {
+ getInitialValueSetter(type).invoke(mScript, getInitialValue(type));
+ }
+
+ for (String type1: sTwoElementStructTypes) {
+ for (String type2: sTwoElementStructTypes) {
+ // Build the input allocation.
+ String tag = type1 + "_" + type2;
+ Class<?> scriptFieldClass = Class.forName(
+ "android.renderscript.cts.ScriptField_two_element_struct_" + tag);
+
+ Object field = scriptFieldClass.getConstructor(RenderScript.class, int.class)
+ .newInstance(mRS, sAllocationElements);
+ Allocation alloc = (Allocation) scriptFieldClass.getMethod("getAllocation")
+ .invoke(field);
+
+ // Set the structure fields of the input.
+ for (int elem = 0; elem < sAllocationElements; ++elem) {
+ Object initialValueA = getInitialValue(type1);
+ // void set_a(int index, Ty val, boolean copyNow)
+ Method fieldASetter = scriptFieldClass.getMethod("set_a",
+ int.class, getUnwrappedClassForType(type1), boolean.class);
+ fieldASetter.invoke(field, elem, initialValueA, true);
+
+ Object initialValueB = getInitialValue(type2);
+ // void set_b(int index, Ty val, boolean copyNow)
+ Method fieldBSetter = scriptFieldClass.getMethod("set_b",
+ int.class, getUnwrappedClassForType(type2), boolean.class);
+ fieldBSetter.invoke(field, elem, initialValueB, true);
+ }
+
+ // Get methods used in testing.
+ Method modify = ScriptC_small_structs.class.getMethod(
+ "forEach_modify_two_element_struct_" + tag,
+ Allocation.class, Allocation.class);
+
+ Method verify = ScriptC_small_structs.class.getMethod(
+ "invoke_verify_two_element_struct_" + tag,
+ Allocation.class);
+
+ // Run the test.
+ modify.invoke(mScript, alloc, alloc);
+ verify.invoke(mScript, alloc);
+ }
+ }
+
+ checkForErrorsInScript();
+
+ // Check that all tests were run.
+ mScript.invoke_checkNumberOfTwoElementStructTestsRun();
+ waitForMessage();
+ checkForErrors();
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/BlurStack.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/BlurStack.java
new file mode 100644
index 0000000..391ddb2
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/BlurStack.java
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * An object that contains all the parameters that are needed in refocusing
+ * filtering function, including the range of depth levels, the disc blur radius
+ * of each depth level, how the depth levels are grouped into layers, which
+ * layer is in focus.
+ *
+ * <b> Here by "depth", we mean inverse depth. Pixels with larger depth values
+ * are closer to the camera.
+ *
+ * For a layer n, its depth interval is (@code [layerInfo[n].backDepth,
+ * layerInfo[n].frontDepth]), where (@code backDepth<=frontDepth).
+ *
+ * The layers are ordered from near to far; note that near layers have larger
+ * depth values.
+ *
+ * (@code focusLayer) is the index of the layer that is in focus, that is, has
+ * zero blur.
+ */
+
+public class BlurStack {
+ //private static final Log.Tag TAG = new Log.Tag("BlurStack");
+ private static final String TAG = "BlurStack";
+ /**
+ * The cap for disc radius of blur kernels.
+ */
+ private static final float MAX_DISC_RADIUS = 25.0f;
+
+ /**
+ * The minimum of the interval that is used to group depth levels into
+ * blending layers based on the corresponding blur disk radius.
+ */
+ private static final float MIN_DISK_RADIUS_STEP_SIZE = 2.0f;
+
+ /**
+ * The starting index of depth quantization level. Must be positive as zero is
+ * reserved for invalid depth.
+ */
+ private static final int MIN_DEPTH = 1;
+
+ /**
+ * The ending index of depth quantization level. It must be a power of 2.
+ */
+ private static final int MAX_DEPTH = 64;
+
+ /**
+ * The scale to apply to 8-bit depthmaps.
+ */
+ private static final int DEPTH_SCALE = 256 / MAX_DEPTH;
+
+ /**
+ * For each depth value {@code d} within [MIN_DEPTH,MAX_DEPTH], its blur disc
+ * radius is saved in {@code diskRadius[d-MIN_DEPTH]}. Hence the length
+ * {@code diskRadius} is {@code MAX_DEPTH-MIN_DEPTH+1}.
+ */
+ private float[] diskRadiusArray;
+
+ /**
+ * A set of non-overlapping layers that covers all the depth levels. The
+ * layers are ordered from front (closer to the camera) to back (farther away
+ * from the camera).
+ */
+ private LayerInfo[] layerInfo;
+
+ /**
+ * The layer in which the focal depth belongs to. <b> For this layer, we
+ * assume that it is a single depth layer. That is, the front depth and back
+ * depth both equal to focal depth.
+ */
+ private int focusLayer;
+
+ public static float getMaxDiskRadius() {
+ return MAX_DISC_RADIUS;
+ }
+
+ /**
+ * Returns the blur disk radius of a depth level.
+ *
+ * @param depth depth level
+ * @return the blur disk radius of the depth level
+ */
+ public float getDiskRadius(int depth) {
+ return diskRadiusArray[depth - MIN_DEPTH];
+ }
+
+ public int getNumLayers() {
+ return layerInfo.length;
+ }
+
+ public LayerInfo getLayerInfo(int layer) {
+ return layerInfo[layer];
+ }
+
+ /**
+ * Returns the number of depths in a given layer.
+ *
+ * @param layer layer index
+ * @return the number of depth levels in the layer
+ */
+ public int getNumDepths(int layer) {
+ return layerInfo[layer].frontDepth - layerInfo[layer].backDepth + 1;
+ }
+
+ public int getFocusLayer() {
+ return focusLayer;
+ }
+
+ /**
+ * Returns the depth given the layer and the relative depth in the layer.
+ *
+ * @param layer the layer index
+ * @param relativeDepthInLayer the relative depth index relative to the back
+ * depth of a layer
+ * @return the depth
+ */
+ public int getDepth(int layer, int relativeDepthInLayer) {
+ return layerInfo[layer].backDepth + relativeDepthInLayer;
+ }
+
+ /**
+ * Creates an instance of BlurStack using depth range, focal depth, desired
+ * amount of blur at infinity, and the number of blending layers.
+ *
+ * @param depthTransform an object that translates between floating depth and
+ * quantized depth.
+ * @param focusDepth3D focus depth in 3D
+ * @param depthOfField the range of depth values around focus depth 3D that
+ * has zero blur.
+ * @param blurInfinity the desired amount of blur, represented as blur radius
+ * at infinity
+ * @param numBlendingLayers the number of blending layers that group all the
+ * depth levels
+ * @return an instance of {@code BlurStack}
+ */
+ public static BlurStack createFromDepthTransform(
+ final DepthTransform depthTransform, float focusDepth3D,
+ float depthOfField, float blurInfinity, int numBlendingLayers) {
+ BlurStack blurStack = new BlurStack();
+ // Finds the front and back depth levels for the focus layer.
+ if (depthOfField < 0) {
+ depthOfField = -depthOfField;
+ Log.e(TAG, "Negative depth of field");
+ }
+ int frontFocalDepth = openglDepthToStackDepth(
+ depthTransform.quantize(focusDepth3D * (1 - depthOfField)));
+ int backFocalDepth = openglDepthToStackDepth(
+ depthTransform.quantize(focusDepth3D * (1 + depthOfField)));
+ // Computes blur disk radius for all the depth levels.
+ blurStack.computeDiskRadius(depthTransform, frontFocalDepth, backFocalDepth,
+ blurInfinity);
+
+ if (numBlendingLayers >= MAX_DEPTH) {
+ blurStack.generateOneLayerForEachDepth(frontFocalDepth, backFocalDepth);
+ } else {
+ // Sets the max variation of blur disk radius in a blending layer.
+ float diskRadiusInterval = (blurStack.getDiskRadius(MIN_DEPTH)
+ + blurStack.getDiskRadius(MAX_DEPTH)) / numBlendingLayers;
+ diskRadiusInterval =
+ Math.max(diskRadiusInterval, MIN_DISK_RADIUS_STEP_SIZE);
+ // Computes {@code layerInfo, focusLayer}, assuming {@code diskRadius}
+ // have been computed.
+ blurStack.groupDepthLevelsIntoLayers(frontFocalDepth, backFocalDepth,
+ diskRadiusInterval);
+ }
+ return blurStack;
+ }
+
+ @Override
+ public String toString() {
+ String s = "disparity range: " + MAX_DEPTH + ", " + MIN_DEPTH + "\n";
+ s += "focus disparity: " + layerInfo[focusLayer].frontDepth + ", "
+ + layerInfo[focusLayer].backDepth + "\n";
+ s += "num of layers: " + getNumLayers() + "\n";
+ s += "focus layer: " + focusLayer + "\n";
+
+ for (int n = 0; n < layerInfo.length; ++n) {
+ int front = layerInfo[n].frontDepth;
+ int back = layerInfo[n].backDepth;
+ s += "\nlayer " + n + " num of disparities " + (front - back + 1) + "\n";
+
+ for (int d = front; d >= back; --d) {
+ s += "layer " + n + " disparity " + d + " disk radius "
+ + getDiskRadius(d) + "\n";
+ }
+ }
+
+ return s;
+ }
+
+ /**
+ * OpenGL depth is from 0(near) to 255(far). The depth in BlurStack is from
+ * 1(far) to MAX_DEPTH(near). Converts from openglDepth to stackDepth.
+ *
+ * @param openglDepth openGL depth.
+ * @return stackDepth stack depth.
+ */
+ private static int openglDepthToStackDepth(int openglDepth) {
+ return MAX_DEPTH - (openglDepth / DEPTH_SCALE);
+ }
+
+ /**
+ * OpenGL depth is from 0(near) to 255(far). The depth in BlurStack is from
+ * 1(far) to MAX_DEPTH(near). Converts from stackDepth to openglDepth.
+ *
+ * @param stackDepth stack depth.
+ * @return openglDepth openGL depth.
+ */
+ private static int stackDepthToOpenglDepth(int stackDepth) {
+ return (MAX_DEPTH - stackDepth) * DEPTH_SCALE;
+ }
+
+ /**
+ * A private constructor that forces users to use {@code createFromDepthRange}
+ * to construct an instance of BlurStack.
+ */
+ private BlurStack() {}
+
+ /**
+ * Quantizes the depth range into MAX_DEPTH levels in inverse depth space, and
+ * for each level, computes the blur disk radius.
+ *
+ * @param depthTransform an object that translates between floating depth and
+ * quantized depth.
+ * @param frontFocalDepth front focal depth level
+ * @param backFocalDepth back focal depth level
+ * @param blurInfinity the amount of desired blur represented as the blur
+ * radius at infinity
+ */
+ private void computeDiskRadius(final DepthTransform depthTransform,
+ int frontFocalDepth, int backFocalDepth, float blurInfinity) {
+ int numLevels = MAX_DEPTH - MIN_DEPTH + 1;
+ diskRadiusArray = new float[numLevels];
+ float frontFocalDepth3D =
+ depthTransform.reconstruct(stackDepthToOpenglDepth(frontFocalDepth));
+ float backFocalDepth3D =
+ depthTransform.reconstruct(stackDepthToOpenglDepth(backFocalDepth));
+
+ // Computes the blur disk radius for each depth level.
+ for (int depth = MIN_DEPTH; depth <= MAX_DEPTH; ++depth) {
+ float depth3D =
+ depthTransform.reconstruct(stackDepthToOpenglDepth(depth));
+ float radius = 0;
+ if (depth3D < frontFocalDepth3D) {
+ radius = blurInfinity * (frontFocalDepth3D - depth3D) / depth3D;
+ } else if (depth3D > backFocalDepth3D) {
+ radius = blurInfinity * (depth3D - backFocalDepth3D) / depth3D;
+ }
+ diskRadiusArray[depth - MIN_DEPTH] = Math.min(radius, MAX_DISC_RADIUS);
+ }
+ }
+
+ /**
+ * Sets up {@code focusLayer} such that each layer contains only a single
+ * depth, except that the focal layer contains frontFocalDepth and
+ * backFocalDepth.
+ *
+ * <b> This function computes {@code layerInfo, focusLayer}.
+ *
+ * @param frontFocalDepth the front depth of focal layer.
+ * @param backFocalDepth the back depth of focal layer.
+ */
+ private void generateOneLayerForEachDepth(int frontFocalDepth,
+ int backFocalDepth) {
+ int numLayers =
+ MAX_DEPTH - MIN_DEPTH + 1 - (frontFocalDepth - backFocalDepth);
+ layerInfo = new LayerInfo[numLayers];
+
+ // Pushes single depth layers in front of the focal layer to layerInfo.
+ int layer = 0;
+ for (int depth = MAX_DEPTH; depth > frontFocalDepth; --depth, ++layer) {
+ layerInfo[layer] = new LayerInfo(depth);
+ }
+
+ // Pushes focal layer to layerInfo.
+ focusLayer = layer;
+ layerInfo[layer] = new LayerInfo(frontFocalDepth, backFocalDepth);
+ ++layer;
+
+ // Pushes single depth layers behind the focal layer to layerInfo.
+ for (int depth = backFocalDepth - 1; depth >= MIN_DEPTH; --depth, ++layer) {
+ layerInfo[layer] = new LayerInfo(depth);
+ }
+ }
+
+ /**
+ * Sets up {@code focusLayer} such that within each layer, the blur radius
+ * variation due to depth difference is no larger than
+ * {@code diskRadiusInterval}.
+ *
+ * <b> This function computes {@code layerInfo, focusLayer}, assuming that
+ * {@code diskRadius} have been properly initialized.
+ *
+ * @param frontFocalDepth the front depth of focal layer.
+ * @param backFocalDepth the back depth of focal layer.
+ * @diskRadiusInterval the max allowed blur disk radius difference within each
+ * layer.
+ */
+ private void groupDepthLevelsIntoLayers(int frontFocalDepth,
+ int backFocalDepth, float diskRadiusInterval) {
+ // Groups depth levels behind the focal depth into several layers.
+ // The blur radius difference in each layer is no larger than
+ // diskRadiusInterval.
+ ArrayList<LayerInfo> layerInfoBehindFocus =
+ groupDepthLevelsBehindFocus(backFocalDepth, diskRadiusInterval);
+
+ // Groups depth levels in front of the focal depth into several layers.
+ // The blur radius difference in each layer is no larger than {@code
+ // diskRadiusInterval}.
+ ArrayList<LayerInfo> layerInfoInFrontOfFocus =
+ groupDepthLevelsInFrontOfFocus(frontFocalDepth, diskRadiusInterval);
+
+ // Merges the two groups of layers into one stack of layers, plus the focus
+ // depth layer.
+ int numLayers =
+ layerInfoInFrontOfFocus.size() + 1 + layerInfoBehindFocus.size();
+ layerInfo = new LayerInfo[numLayers];
+ focusLayer = layerInfoInFrontOfFocus.size();
+
+ // The merged layers is ordered from the front-most layer to the back-most
+ // layer.
+ for (int n = 0; n < numLayers; ++n) {
+ if (n < layerInfoInFrontOfFocus.size()) {
+ // Finds the corresponding layer index m in layerInfoInFrontOfFocus,
+ // which is ordered from focal depth to front-most.
+ int m = (layerInfoInFrontOfFocus.size() - 1) - n;
+ layerInfo[n] = layerInfoInFrontOfFocus.get(m);
+ } else if (n == layerInfoInFrontOfFocus.size()) {
+ layerInfo[n] = new LayerInfo(frontFocalDepth, backFocalDepth);
+ } else {
+ // Finds the corresponding layer index m in layerInfoBehindFocus, which
+ // is ordered from focal depth to back-most.
+ int m = n - (layerInfoInFrontOfFocus.size() + 1);
+ layerInfo[n] = layerInfoBehindFocus.get(m);
+ }
+ }
+ }
+
+ /**
+ * Groups depth levels behind the focal depth into several layers. The blur
+ * radius difference in each layer is no larger than
+ * {@code diskRadiusInterval}.
+ *
+ * @param backFocalDepth the back depth of focal layer.
+ * @param diskRadiusInterval max disk radius variation in each layer
+ * @return layerInfo layering of depth levels behind the focal depth
+ */
+ private ArrayList<LayerInfo> groupDepthLevelsBehindFocus(int backFocalDepth,
+ float diskRadiusInterval) {
+ // Initializes the layerInfo array with maximum capacity needed.
+ ArrayList<LayerInfo> layerInfo =
+ new ArrayList<LayerInfo>(diskRadiusArray.length);
+
+ if (backFocalDepth == MIN_DEPTH) {
+ return layerInfo;
+ }
+
+ // At this point, focusDepth > minDepth.
+ // Moves to the first depth behind the focus depth and initializes a layer.
+ int d = backFocalDepth - 1;
+ layerInfo.add(new LayerInfo(d));
+ // Sets up the max radius threshold for the layer.
+ float radiusThreshold = getDiskRadius(d) + diskRadiusInterval;
+
+ // Expands the layer to include depth levels so long as the blur disk
+ // radius within the layer is not larger than radiusThreshold.
+ // Stops the expansion when current depth is already the minDepth.
+ while (d > MIN_DEPTH) {
+ // Moves to the next depth.
+ d--;
+ if (getDiskRadius(d) <= radiusThreshold) {
+ // Expands the current layer by lowering its back depth.
+ int numLayers = layerInfo.size();
+ layerInfo.get(numLayers - 1).backDepth = d;
+ } else {
+ // Generates a new single-depth layer.
+ // Expands it in the next iteration if necessary.
+ layerInfo.add(new LayerInfo(d));
+ radiusThreshold = getDiskRadius(d) + diskRadiusInterval;
+ }
+ }
+ return layerInfo;
+ }
+
+ /**
+ * Groups depth levels in front of the focal depth into several layers. The
+ * blur radius difference in each layer is no larger than
+ * {@code diskRadiusInterval}.
+ *
+ * @param frontFocalDepth the back depth of focal layer.
+ * @param diskRadiusInterval max disk radius variation in each layer
+ * @return layerInfo layering of depth levels behind the focal depth
+ */
+ private ArrayList<LayerInfo> groupDepthLevelsInFrontOfFocus(
+ int frontFocalDepth, float diskRadiusInterval) {
+ // Initializes the layerInfo array with maximum capacity needed.
+ ArrayList<LayerInfo> layerInfo =
+ new ArrayList<LayerInfo>(diskRadiusArray.length);
+
+ if (frontFocalDepth == MAX_DEPTH) {
+ return layerInfo;
+ }
+
+ // At this point, focusDepth < maxDepth.
+ // Moves to the first depth in front of the focus depth and initializes a
+ // layer.
+ int d = frontFocalDepth + 1;
+ layerInfo.add(new LayerInfo(d));
+ // Sets up the max radius threshold for the layer.
+ float radiusThreshold = getDiskRadius(d) + diskRadiusInterval;
+
+ // Expands the layer to include depth levels so long as the blur disk
+ // radius within the layer is not larger than radiusThreshold.
+ // Stops the expansion when current depth is already the maxDepth.
+ while (d < MAX_DEPTH) {
+ // Moves to the next depth.
+ d++;
+ if (getDiskRadius(d) <= radiusThreshold) {
+ // Expands the current layer by increasing its front depth.
+ int numLayers = layerInfo.size();
+ layerInfo.get(numLayers - 1).frontDepth = d;
+ } else {
+ // Generates a new single-depth layer.
+ // Expands it in the next iteration if necessary.
+ layerInfo.add(new LayerInfo(d));
+ radiusThreshold = getDiskRadius(d) + diskRadiusInterval;
+ }
+ }
+ return layerInfo;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthImage.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthImage.java
new file mode 100644
index 0000000..d626650
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthImage.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.net.Uri;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class DepthImage {
+ private final String mFormat;
+ private final double mFar;
+ private final double mNear;
+ private final Bitmap mDepthBitmap;
+ private final double mBlurAtInfinity;
+ private final double mFocalDistance;
+ private final double mDepthOfFiled;
+ private final double mFocalPointX;
+ private final double mFocalPointY;
+ private final DepthTransform mDepthTransform;
+ public DepthImage(Context context, Uri data) throws IOException {
+ InputStream input = context.getContentResolver().openInputStream(data);
+ XmpDepthDecode decode = new XmpDepthDecode(input);
+ mFormat = decode.getFormat();
+ mFar = decode.getFar();
+ mNear = decode.getNear();
+ mDepthBitmap = decode.getDepthBitmap();
+ mBlurAtInfinity = decode.getBlurAtInfinity();
+ mFocalDistance = decode.getFocalDistance();
+ mDepthOfFiled = decode.getDepthOfField();
+ mFocalPointX = decode.getFocalPointX();
+ mFocalPointY = decode.getFocalPointY();
+ input = context.getContentResolver().openInputStream(data);
+ mDepthTransform = decode.getDepthTransform();
+ }
+
+ public Bitmap getDepthBitmap() {
+ return mDepthBitmap;
+ }
+
+ public DepthTransform getDepthTransform() { return mDepthTransform; }
+
+ public String getFormat() {
+ return mFormat;
+ }
+
+ public double getFar() {
+ return mFar;
+ }
+
+ public double getNear() {
+ return mNear;
+ }
+
+ public double getBlurAtInfinity() {
+ return mBlurAtInfinity;
+ }
+
+ public double getFocalDistance() {
+ return mFocalDistance;
+ }
+
+ public double getDepthOfField() {return mDepthOfFiled; }
+
+ public double getFocalPointX() {
+ return mFocalPointX;
+ }
+
+ public double getFocalPointY() {
+ return mFocalPointY;
+ }
+}
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthOfFieldOptions.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthOfFieldOptions.java
new file mode 100644
index 0000000..7bc9068
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthOfFieldOptions.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+/**
+ * A struct containing all the data needed to apply a depth-of-field effect.
+ */
+public class DepthOfFieldOptions {
+ public final RGBZ rgbz;
+ public float focalDepth;
+ public float blurInfinity;
+ // The depth of field specifies the depth range in focus (i.e., zero blur) as
+ // a ratio of the focal depth. Its range is [0, 1). The depth of field range
+ // in depth units is computed as
+ // [(1 - depthOfField) * focalDepth,(1 + depthOfField) * focalDepth].
+ public float depthOfField;
+
+ /**
+ * Creates a {@code DepthOfFieldOptions} from an {@code RGBZ}.
+ *
+ * @param rgbz the {@code RGBZ} to render
+ */
+ public DepthOfFieldOptions(RGBZ rgbz) {
+ this.focalDepth = (float)rgbz.getFocusDepth();
+ this.depthOfField = (float)rgbz.getDepthOfField();
+ this.blurInfinity = (float)rgbz.getBlurInfinity() * Math.max(rgbz.getHeight(), rgbz.getWidth());
+ this.rgbz = rgbz;
+ }
+
+ public void setFocusPoint(float x, float y) {
+ this.focalDepth = rgbz.getDepth((int)(x * rgbz.getWidth()), (int)(y * rgbz.getHeight()));
+ //this.blurInfinity = lensController.blurInfinityFromAverageBlur(this.focalDepth, this.depthOfField, averageBlur);
+ //System.out.println("new focal depth: " + this.focalDepth);
+ }
+
+ public void setBokeh(float bokeh) {
+ this.blurInfinity = bokeh * 200;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthTransform.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthTransform.java
new file mode 100644
index 0000000..f79003a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/DepthTransform.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+/**
+ * Interface defining a depth transform that translates real depth values
+ * into an 8-bit quantized representation.
+ */
+public interface DepthTransform {
+ /**
+ * @return The near depth value
+ */
+ public float getNear();
+
+ /**
+ * @return The far depth value
+ */
+ public float getFar();
+
+ /**
+ * @return The format of the transform
+ */
+ public String getFormat();
+
+ /**
+ * @return the quantized value that corresponds to the given depth value
+ */
+ public int quantize(float depth);
+
+ /**
+ * @return the depth value that corresponds to the given quantized value
+ */
+ public float reconstruct(int value);
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageBuffersForRenderScript.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageBuffersForRenderScript.java
new file mode 100644
index 0000000..9078764
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageBuffersForRenderScript.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+
+/**
+ * A class that manages the image buffers that interface between Java and Render
+ * Script. This class will be specialized for float in f32 package and for byte
+ * in u8 package.
+ */
+public class ImageBuffersForRenderScript {
+ /**
+ * Input and output images and their corresponding Allocation to interface
+ * with Render Script. Both input and output images are unpadded images.
+ */
+ public Bitmap inputImage;
+ public Bitmap outputImage;
+ public Allocation inAllocation;
+ public Allocation outAllocation;
+
+ /**
+ * The following three member variables are used in the subclasses that extend
+ * this class. Therefore, they are protected.
+ */
+ public int imageWidthPadded;
+ public int imageHeightPadded;
+ public int paddedMargin;
+
+ public ImageBuffersForRenderScript(Bitmap inImage, int margin,
+ RenderScript renderScript) {
+ inputImage = inImage;
+ inAllocation = Allocation.createFromBitmap(renderScript, inputImage);
+
+ outputImage = Bitmap.createBitmap(inputImage.getWidth(),
+ inputImage.getHeight(), Bitmap.Config.ARGB_8888);
+ outAllocation = Allocation.createFromBitmap(renderScript, outputImage);
+
+ paddedMargin = margin;
+ imageWidthPadded = inputImage.getWidth() + 2 * margin;
+ imageHeightPadded = inputImage.getHeight() + 2 * margin;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageCompare.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageCompare.java
new file mode 100644
index 0000000..4f15b0a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/ImageCompare.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.graphics.Bitmap;
+
+import java.nio.ByteBuffer;
+
+public class ImageCompare {
+
+ private static byte[] loadBitmapByteArray(Bitmap bitmap) {
+ int bytes = bitmap.getByteCount();
+ ByteBuffer buffer = ByteBuffer.allocate(bytes);
+ bitmap.copyPixelsToBuffer(buffer);
+ byte[] array = buffer.array();
+ return array;
+ }
+
+ public static class CompareValue {
+ float aveDiff = 0f;
+ float diffPercent = 0f;
+ }
+
+ public static void compareBitmap(Bitmap bitmap1, Bitmap bitmap2, CompareValue result) {
+
+ if (bitmap1.getWidth() != bitmap2.getWidth() || bitmap1.getHeight() != bitmap2.getHeight()) {
+ throw new RuntimeException("images were of diffrent size");
+ }
+
+ byte[] first = loadBitmapByteArray(bitmap1);
+ byte[] second = loadBitmapByteArray(bitmap2);
+ int loopCount = first.length;
+
+ int diffCount = 0;
+ long diffSum = 0;
+ for (int i = 0; i < loopCount; i++) {
+ int v1 = 0xFF & first[i];
+ int v2 = 0xFF & second[i];
+ int error = Math.abs(v1 - v2);
+ if (error > 0) {
+ diffCount++;
+ diffSum += error;
+ }
+ }
+ result.diffPercent = ((float) diffCount) / first.length;
+ result.aveDiff = ((float) diffSum) / first.length;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/KernelDataForRenderScript.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/KernelDataForRenderScript.java
new file mode 100644
index 0000000..3b9139b
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/KernelDataForRenderScript.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+
+/**
+ * A class that manages the blur kernel matrices of a blending layer that
+ * interface between Java and Render Script. This class will be specialized for
+ * float in f32 package and for byte in u8 package.
+ *
+ */
+public class KernelDataForRenderScript {
+ /**
+ * A flag to turn on using optimized RenderScript.
+ * False means using original version; true means using the new version.
+ */
+ private static boolean UseNewRS = false;
+
+ /**
+ * Number of sub-pixels that is used to generate anti-aliased blur kernel
+ * matrix. That is, we divide one pixel into
+ * {@code NUM_SUB_PIXELS * NUM_SUB_PIXELS} sub-pixels to test whether or not a
+ * pixel is in the blur disk.
+ */
+ protected static final int NUM_SUB_PIXELS = 5;
+
+ /**
+ * The width of the pixels that are used to pad the image boundary to avoid
+ * boundary checking in filtering operation.
+ */
+ private static final int MAX_KERNEL_RADIUS =
+ computeKernelRadiusFromDiskRadius(BlurStack.getMaxDiskRadius());
+
+ /**
+ * The length of an array that concatenates all (vectorized) kernel matrices.
+ */
+ protected int stackLength;
+
+ /**
+ * A class automatically generated by Render Script compiler, which contains
+ * required auxiliary information to parse {@code kernelStack}, including the
+ * starting position of each kernel matrix in a memory buffer and the radius
+ * (radius_x,radius_y) of each kernel matrix. The names radius_x and radius_y
+ * follow C++ style because render script is C language.
+ */
+ protected ScriptField_KernelInfo kernelInfo;
+
+ /**
+ * Java array version of the current kernel info. Used when UseNewRS is true.
+ * 4*m: offset; 4*m + 1: radius_x; 4*m + 2: radius_y
+ */
+ protected float[] infoArray;
+
+ /**
+ * An allocation used to store global allocation of stack info. Used when UseNewRS is true.
+ */
+ public Allocation infoAllocation;
+
+ public static int getNumSubPixels() {
+ return NUM_SUB_PIXELS;
+ }
+
+ public static int getMaxKernelRadius() {
+ return MAX_KERNEL_RADIUS;
+ }
+
+ public static void setUseNewRS(boolean choice) {
+ UseNewRS = choice;
+ }
+
+ /**
+ * Computes the kernel matrix radius from the blur disk radius.
+ *
+ * @param diskRadius blur disk radius
+ * @return kernel matrix radius
+ */
+ public static int computeKernelRadiusFromDiskRadius(float diskRadius) {
+ return (int) (diskRadius) + 1;
+ }
+
+ public ScriptField_KernelInfo getKernelInfo() {
+ return kernelInfo;
+ }
+
+ /**
+ * Initializes {@code kernelInfo}.
+ *
+ * @param targetLayer the index of a target layer
+ * @param blurStack an instance of {@code BlurStack}
+ * @param renderScript an instance of {@code RenderScript}
+ */
+ protected KernelDataForRenderScript(int targetLayer, BlurStack blurStack,
+ RenderScript renderScript) {
+ if (UseNewRS) {
+ // Use the new version of renderscript files.
+ int numDepths = blurStack.getNumDepths(targetLayer);
+ infoAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ numDepths);
+
+ infoArray = new float[4 * numDepths];
+ // Generates information for each blur kernel matrix.
+ int offset = 0;
+ for (int m = 0; m < numDepths; ++m) {
+ int depth = blurStack.getDepth(targetLayer, m);
+ float diskRadius = blurStack.getDiskRadius(depth);
+ int kernelRadius = computeKernelRadiusFromDiskRadius(diskRadius);
+
+ infoArray[m * 4] = offset;
+ infoArray[m * 4 + 1] = kernelRadius;
+ infoArray[m * 4 + 2] = kernelRadius;
+
+ // Updates offset variable.
+ int kernelLength = (2 * kernelRadius + 1) * (2 * kernelRadius + 1);
+ offset += kernelLength;
+ }
+ infoAllocation.copyFrom(infoArray);
+ stackLength = offset;
+ } else {
+ // Use original version of renderscript files.
+ int numDepths = blurStack.getNumDepths(targetLayer);
+ kernelInfo = new ScriptField_KernelInfo(renderScript, numDepths);
+
+ // Generates information for each blur kernel matrix.
+ int offset = 0;
+ for (int m = 0; m < numDepths; ++m) {
+ int depth = blurStack.getDepth(targetLayer, m);
+ float diskRadius = blurStack.getDiskRadius(depth);
+ int kernelRadius = computeKernelRadiusFromDiskRadius(diskRadius);
+ // Sets information for the {@code m}'th kernel matrix.
+ kernelInfo.set_offset(m, offset, true);
+ kernelInfo.set_radius_x(m, kernelRadius, true);
+ kernelInfo.set_radius_y(m, kernelRadius, true);
+ // Updates offset variable.
+ int kernelLength = (2 * kernelRadius + 1) * (2 * kernelRadius + 1);
+ offset += kernelLength;
+ }
+ stackLength = offset;
+ }
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/LayerInfo.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/LayerInfo.java
new file mode 100644
index 0000000..2cdbd69
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/LayerInfo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+/**
+ * An object that defines a blending layer for refocus rendering, which groups
+ * several consecutive depth levels.
+ */
+public class LayerInfo {
+ public int frontDepth;
+ public int backDepth;
+
+ LayerInfo(int depth) {
+ frontDepth = depth;
+ backDepth = depth;
+ }
+
+ LayerInfo(int front, int back) {
+ frontDepth = front;
+ backDepth = back;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/MediaStoreSaver.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/MediaStoreSaver.java
new file mode 100644
index 0000000..a97af3a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/MediaStoreSaver.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Environment;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Utility class to save images into android image database
+ */
+public class MediaStoreSaver {
+ public static final String savePNG(Bitmap bitmap,
+ String folderName,
+ String imageName,
+ Context mContext) {
+ File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
+ String folder_path = folder.getAbsolutePath();
+ String file_path = folder_path + "/" + folderName;
+ File dir = new File(file_path);
+
+ if (!dir.exists()) {
+ System.out.println("make directory: " + dir.getAbsolutePath());
+ dir.mkdirs();
+ }
+ File file = null;
+ try {
+ file = File.createTempFile( imageName, ".png",dir);
+ FileOutputStream fOut = new FileOutputStream(file);
+ bitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
+ System.out.println("saved image: " + file.getAbsolutePath());
+ fOut.flush();
+ fOut.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ MediaStorageScan(mContext, file);
+ return file.getAbsolutePath();
+ }
+ /*
+ * Refresh image files to view them on computer
+ */
+ private static void MediaStorageScan(Context context, final File file) {
+ final Uri fileUri = Uri.fromFile(file);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ context.sendBroadcast(new Intent("android.hardware.action.NEW_PICTURE", fileUri));
+ }
+
+ context.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", fileUri));
+
+ final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(fileUri);
+ context.sendBroadcast(intent);
+ }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/RGBZ.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RGBZ.java
new file mode 100644
index 0000000..f882247
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RGBZ.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.net.Uri;
+import android.util.Log;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * An RGBZ image, where Z stands for depth, i.e. a color+depth image.
+ * The RGBZ always has a preview image, which represents the latest rendering of the RGBZ.
+ * The preview is encoded as the normal jpeg content for client compatibility,
+ * while the color channel and depth channels are encoded as XMP data.
+ * The class supports lazy initialization where the XMP meta data is loaded only when first
+ * accessed.
+ */
+public class RGBZ {
+ public static final String TAG = "RGBZ";
+
+ private Bitmap bitmap;
+ private Bitmap preview;
+ private Bitmap depthBitmap;
+ private DepthTransform depthTransform;
+ private DepthImage depthImage;
+
+ /**
+ * Creates an RGBZ from a content uri.
+ *
+ * @param uri The uri name of the RGBZ
+ * @throws FileNotFoundException if the RGBZ could not be read
+ */
+ public RGBZ(Uri uri, ContentResolver contentResolver, Context context) throws IOException {
+ preview = BitmapFactory.decodeStream(contentResolver.openInputStream(uri));
+ if (preview == null) {
+ throw new FileNotFoundException(uri.toString());
+ }
+ this.depthImage = new DepthImage(context, uri);
+ this.depthBitmap = depthImage.getDepthBitmap();
+ this.bitmap = setAlphaChannel(preview, this.depthBitmap);
+ this.depthTransform = depthImage.getDepthTransform();
+ }
+
+ /**
+ * @return Whether the RGBZ has a depth channel
+ */
+ public boolean hasDepthmap() {
+ return depthTransform != null;
+ }
+
+ /**
+ * @return The color+depth {@code Bitmap}
+ */
+ public Bitmap getBitmap() {
+ return bitmap;
+ }
+
+ /**
+ * @return The depthmap component of this RGBZ
+ */
+ public DepthTransform getDepthTransform() {
+ return depthTransform;
+ }
+
+ public double getFocusDepth() {
+ return this.depthImage.getFocalDistance();
+ }
+
+ public double getDepthOfField() {
+ return this.depthImage.getDepthOfField();
+ }
+
+ public double getBlurInfinity() {
+ return this.depthImage.getBlurAtInfinity();
+ }
+
+ /**
+ * @return the width of this {@code RGBZ}
+ */
+ public int getWidth() {
+ return bitmap.getWidth();
+ }
+
+ /**
+ * @return the height of this {@code RGBZ}
+ */
+ public int getHeight() {
+ return bitmap.getHeight();
+ }
+
+ /**
+ * @return the depth value of the given pixel
+ */
+
+ public float getDepth(int x, int y) {
+ if (!hasDepthmap()) {
+ return 0.0f;
+ }
+ if (x < 0 || x > depthBitmap.getWidth() ||
+ y < 0 || y > depthBitmap.getHeight()) {
+ Log.e("RGBZ getDepth", "index out of bound");
+ return 0;
+ }
+ return getDepthTransform().reconstruct(Color.blue(depthBitmap.getPixel(x, y)));
+ }
+
+ /**
+ * Sets the depthmap as the alpha channel of the {@code Bitmap}.
+ */
+ public Bitmap setAlphaChannel(Bitmap bitmap, Bitmap depthBitmap) {
+ if (bitmap == null) {
+ return bitmap;
+ }
+ Bitmap result = bitmap.copy(Bitmap.Config.ARGB_8888, true);
+ // set the alpha channel of depthBitmap to alpha of bitmap
+ result = setAlphaChannelFromBitmap(depthBitmap, bitmap, result);
+ return result;
+ }
+
+ private Bitmap setAlphaChannelFromBitmap(Bitmap depth, Bitmap orig, Bitmap dest) {
+ int w = orig.getWidth();
+ int h = orig.getHeight();
+ int[] orig_data = new int[w*h];
+ int[] depth_data = new int[w*h];
+
+ orig.getPixels(orig_data, 0, w, 0, 0, w, h);
+ depth.getPixels(depth_data, 0, w, 0, 0, w, h);
+ for (int i = 0; i < orig_data.length; i++) {
+ int v = orig_data[i] & 0x00FFFFFF;
+ int temp = (depth_data[i] & 0x000000FF) << 24;
+ v = v | temp;
+ orig_data[i] = v;
+ }
+ dest.setPixels(orig_data, 0, w, 0, 0, w, h);
+ return dest;
+ }
+}
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusFilter.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusFilter.java
new file mode 100644
index 0000000..f8c9f00
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusFilter.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.graphics.Bitmap;
+import android.renderscript.RenderScript;
+import android.util.Log;
+
+/**
+ * An abstract class that implements refocus filtering using Render Script. The
+ * main function is {@code compute}. All other functions and data structures are
+ * supporting this main function. Subclasses need to implement individual steps
+ * based on pixel representation, e.g., uint8 or float32.
+ *
+ * @param <ScriptType> pixel representation, which can be float of byte.
+ *
+ */
+public abstract class RefocusFilter<ScriptType> {
+ //private static final Log.Tag TAG = new Log.Tag("RefocusFilter");
+ protected static final String TAG = "RefocusFilter";
+ // Render Script context.
+ protected RenderScript renderScript;
+
+ // Script functions in .rs file.
+ protected ScriptType scriptC;
+
+ /*
+ * A constructor that initializes the class.
+ *
+ * @param rs the Render Script context.
+ */
+ public RefocusFilter(RenderScript rs) {
+ renderScript = rs;
+ }
+
+ /*
+ * A function that implements refocus filtering using Render Script.
+ *
+ * @param inputImage an RGBD image. RGB channels of the input image form the
+ * color image. The D channel has a range of [1,BlurStack.MAX_DEPTH], where 0
+ * is reserved for invalid padded pixels. Depth here refers to inverse depth
+ * (i.e., disparity), where larger depths are closer to the camera.
+ *
+ * @param blurStack an object that has all the parameters for refocus
+ * filtering, including: the number of blending layers, the depth levels in
+ * each blending layer, focal depth, etc. For details, please refer to the
+ * definition of {@code BlurStack}.
+ *
+ * @return a {@code Bitmap} of the filtering result
+ */
+ /*
+ Commented out for now to define in derived classes
+ so that images after each stage could be extracted
+ */
+ protected Bitmap compute(Bitmap inputImage, BlurStack blurStack) {
+
+ // Initializes {@code scriptC} and allocates required memory buffers
+ // (defined in subclasses) that interface between Java and Render Script.
+ initializeScriptAndBuffers(inputImage,
+ blurStack.getLayerInfo(blurStack.getFocusLayer()));
+
+ // Processes layers from back-most to focal depth (including the focal
+ // depth).
+ if (!processLayersFromBackToFocus(blurStack)) {
+ return null;
+ }
+
+ // Processes layers from front-most to focal depth (excluding the focal
+ // depth).
+ if (!processLayersFromFrontToFocus(blurStack)) {
+ return null;
+ }
+
+ // Extracts the result from .rs file to Java.
+ Bitmap resultImage = extractResultImage();
+ renderScript.finish();
+
+ Log.d(TAG, "filterAndBlendAllLayersUsingKernel is finished");
+ return resultImage;
+ }
+
+ /*
+ * Process layers from back-most to focal depth (including the focal depth).
+ */
+ protected boolean processLayersFromBackToFocus(BlurStack blurStack) {
+ for (int targetLayer = blurStack.getNumLayers() - 1;
+ targetLayer >= blurStack.getFocusLayer(); --targetLayer) {
+ // Sets up target layer info in Render Script.
+ LayerInfo layerInfo = blurStack.getLayerInfo(targetLayer);
+ setTargetLayer(layerInfo);
+
+ // For a layer that is behind the focal depth, its back depth has the
+ // largest blur kernel radius. Uses the kernel radius as dilation radius
+ // of this layer.
+ int dilationRadius = getKernelRadius(layerInfo.backDepth, blurStack);
+ setBlendInfo(dilationRadius);
+
+ // Sends blur kernel matrix data to Render Script.
+ setKernelData(targetLayer, blurStack);
+
+ // Marks active pixels (pixels that on this layer).
+ // Marks pixels that are close enough (within dilationRadius) to the
+ // active pixels.
+ // Computes distance transform of the active pixels in their neighborhood
+ // and use the distance value as matte for layer blending later.
+ computeLayerMatteBehindFocalDepth();
+
+ // Computes filtering for pixels on the target layer and saves the
+ // filtering result in a buffer {@code g_fuzzy_image} in .rs file.
+ filterLayerBehindFocalDepth();
+
+ // Replaces active pixels in {@code g_sharp_image} with the filtering
+ // result saved in {@code g_fuzzy_image}. The replacement is soft,
+ // blending {@code g_sharp_image} and {@code g_fuzzy_image} using the
+ // computed matte. Uses the blending result as the sharp input image for
+ // the next iteration.
+ updateSharpImageUsingFuzzyImage();
+ }
+ return true;
+ }
+
+ /*
+ * Processes layers from front-most to focal depth (excluding the focal depth)
+ */
+ protected boolean processLayersFromFrontToFocus(BlurStack blurStack) {
+ // At this point, the input image {@code g_sharp_image} has been updated by
+ // the first pass from back-most layer to focus layer {@code
+ // processLayersFromBackToFocus}.
+ for (int targetLayer = 0; targetLayer < blurStack.getFocusLayer();
+ ++targetLayer) {
+ // Sets up target layer info in Render Script.
+ LayerInfo layerInfo = blurStack.getLayerInfo(targetLayer);
+ setTargetLayer(layerInfo);
+
+ // For a layer that is in front of the focal depth, its front depth has
+ // the largest blur kernel radius. Uses the kernel radius as dilation
+ // radius of this layer.
+ int dilationRadius = getKernelRadius(layerInfo.frontDepth, blurStack);
+ setBlendInfo(dilationRadius);
+
+ // Sends blur kernel matrix data to Render Script.
+ setKernelData(targetLayer, blurStack);
+
+ // Marks active pixels (pixels that on this layer).
+ // Marks pixels that are close enough (within dilationRadius) to the
+ // active pixels.
+ // Computes distance transform of the active pixels in their neighborhood
+ // and use the distance value as matte for layer blending later.
+ computeLayerMatteInFrontOfFocalDepth();
+
+ // Computes filtering for pixels on the target layer and accumulates the
+ // filtering result to an buffer {@code g_fuzzy_image} in .rs file.
+ // The accumulating operation is soft, using the computed matte values.
+ filterLayerInFrontOfFocalDepth();
+ }
+
+ // Fills in the pixels on or behind the focal depth in {@code g_fuzzy_image}
+ // using pixels in {@code g_sharp_image}. Does the filling in a soft way by
+ // blending using the matte. Uses the blending result (saved in {@code
+ // g_fuzzy_image}) as the final output image.
+ finalizeFuzzyImageUsingSharpImage();
+ return true;
+ }
+
+ private static int getKernelRadius(int depth, BlurStack blurStack) {
+ int kernelRadius = KernelDataForRenderScript
+ .computeKernelRadiusFromDiskRadius(blurStack.getDiskRadius(depth));
+ return kernelRadius;
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ //
+ // The following abstract functions must be implemented in a subclass.
+ //
+ // ///////////////////////////////////////////////////////////////////////////
+
+ // Initializes the member {@code scriptC} and allocate memory buffers (defined
+ // in a subclass) that interface between Java and .rs file.
+ protected abstract void initializeScriptAndBuffers(Bitmap inputImage,
+ LayerInfo focalLayer);
+
+ // Extracts the result image from memory buffer.
+ protected abstract Bitmap extractResultImage();
+
+ // Sets target layer info in .rs file.
+ protected abstract void setTargetLayer(LayerInfo layerInfo);
+
+ // Sets dilation radius in .rs file for blending target layer.
+ protected abstract void setBlendInfo(int dilationRadius);
+
+ /*
+ * A function that prepares the blur kernels for the target layer and passes
+ * them to the Render Script. Each depth value in the layer has a kernel. The
+ * kernels are packed in a memory buffer. Auxiliary information for parsing
+ * the memory buffer is also prepared and passed to Render Script.
+ *
+ * @param targetLayer the index of a target layer
+ *
+ * @param blurStack a BlurStack object that has the layer structure of the
+ * refocus filter task in Java
+ */
+ protected abstract void setKernelData(int targetLayer, BlurStack blurStack);
+
+ protected abstract void computeLayerMatteBehindFocalDepth();
+
+ protected abstract void filterLayerBehindFocalDepth();
+
+ protected abstract void updateSharpImageUsingFuzzyImage();
+
+ protected abstract void computeLayerMatteInFrontOfFocalDepth();
+
+ protected abstract void filterLayerInFrontOfFocalDepth();
+
+ protected abstract void finalizeFuzzyImageUsingSharpImage();
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusTest.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusTest.java
new file mode 100644
index 0000000..666d9c5
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RefocusTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.RSBaseCompute;
+import android.util.Log;
+
+import com.android.cts.renderscript.R;
+
+import java.io.IOException;
+
+/**
+ * This is a test case for large real world renderscript code
+ * Many subtle issues with renderscript may not be caught by small unit test
+ */
+public class RefocusTest extends RSBaseCompute {
+ /**
+ * Test the orignal and current refocus code
+ */
+ public void testOriginalRefocus() {
+ refocus(RenderScriptTask.script.f32);
+ }
+
+ /**
+ * Test the orignal and current refocus code
+ */
+ public void testNewRefocus() {
+ refocus(RenderScriptTask.script.d1new);
+ }
+
+ /**
+ * Test a refocus operator against the refocus_reference image
+ * @param d1new which version of refocus to run
+ */
+ private void refocus(RenderScriptTask.script d1new) {
+ Context ctx = getContext();
+
+ RenderScript rs = RenderScript.create(ctx);
+ RGBZ current_rgbz = null;
+ try {
+ current_rgbz = new RGBZ(getResourceRef(R.drawable.refocus_image), ctx.getContentResolver(), ctx);
+ } catch (IOException e) {
+ e.printStackTrace();
+ assertNull(e);
+ }
+ DepthOfFieldOptions current_depth_options = new DepthOfFieldOptions(current_rgbz);
+ current_depth_options.setFocusPoint(0.7f, 0.5f);
+ current_depth_options.setBokeh(2f);
+
+ RsTaskParams rsTaskParam = new RsTaskParams(rs, current_depth_options);
+
+ RenderScriptTask renderScriptTask = new RenderScriptTask(rs, d1new);
+ Bitmap outputImage = renderScriptTask.applyRefocusFilter(rsTaskParam.mOptions);
+ Bitmap refrenceImage = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.refocus_reference);
+ ImageCompare.CompareValue result = new ImageCompare.CompareValue();
+
+ ImageCompare.compareBitmap(outputImage, refrenceImage, result);
+ if (result.diffPercent >= 0.0001 && result.aveDiff > 5) {
+ MediaStoreSaver.savePNG(outputImage, "Errors", "RefocusErr" , ctx);
+ assertTrue("% difference from reference = " + (result.diffPercent * 100) +
+ " with avg. diff = " + result.aveDiff, false);
+ }
+ rs.destroy();
+ }
+
+
+ private static class RsTaskParams {
+ RenderScript mRenderScript;
+ DepthOfFieldOptions mOptions;
+
+ RsTaskParams(RenderScript renderScript,
+ DepthOfFieldOptions options) {
+ mRenderScript = renderScript;
+ mOptions = options;
+ }
+ }
+
+ Uri getResourceRef(int resID) {
+ Context context = getContext().getApplicationContext();
+ Uri path = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
+ context.getResources().getResourcePackageName(resID) + '/' +
+ context.getResources().getResourceTypeName(resID) + '/' +
+ context.getResources().getResourceEntryName(resID));
+ return path;
+ }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/RenderScriptTask.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RenderScriptTask.java
new file mode 100644
index 0000000..29436c6
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/RenderScriptTask.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.graphics.Bitmap;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.refocus.d1new.RefocusFilterd1new;
+import android.renderscript.cts.refocus.f32.RefocusFilterF32;
+import android.util.Log;
+
+/**
+ * An wrapper class that calls the refocus filtering function in
+ * {@code RefocusFilter} class. The class also contains several default
+ * parameters that are used in calling the refocus filtering function.
+ *
+ * Example usage:
+ *
+ * {@code DepthOfFieldOptions options;}
+ * {@code RenderScriptTask renderScriptTask;}
+ * {@code Bitmap result = renderScriptTask.applyRefocusFilter(options);}
+ *
+ */
+public class RenderScriptTask {
+ enum script{f32, d1new};
+ /**
+ * A flag to choose the version of RenderScript.
+ */
+ private script mScript = script.d1new;
+
+ /**
+ * An enum for the different types of Render Script tasks. (generated by zhl)
+ */
+ public enum Purpose {
+ VIEWER, SERVICE
+ }
+
+ //private static final Log.Tag TAG = new Log.Tag("RenderScriptTask");
+ private static final String TAG = "RenderScriptTask";
+ /**
+ * Number of blending layers in which the quantized depth levels are grouped.
+ */
+ private static final int NUM_BLENDING_LAYERS = 8;
+
+ /**
+ * An object that records the blur disk radius for each quantized inverse
+ * depth level and how all the depth levels are grouped into blending layers.
+ */
+ public BlurStack blurStack;
+
+ /**
+ * An image in which each pixel has red, green, blue, and quantized inverse
+ * depth level. The quantized inverse depth levels range from 1 to
+ * {@code BlurStack.MAX_DEPTH}. 0 is reserved for padding pixels.
+ *
+ * <b> The pixels with larger depth values are closer to the camera.
+ */
+ private Bitmap rgbdImage;
+
+ /**
+ * The Render Script context that is required to construct the filter.
+ */
+ private RenderScript renderScript;
+
+ /**
+ * A constructor of render script context.
+ *
+ * @param renderScript RenderScript context.
+ */
+ public RenderScriptTask(RenderScript renderScript, script sChoice) {
+ this.renderScript = renderScript;
+ this.mScript = sChoice;
+ }
+
+ /**
+ * A function that computes a refocused image from an instance of
+ * {@code DepthOfFieldOptions}.
+ *
+ * @param options an object contains color image, depth map, focal depth, and
+ * the amount of desired blur ({@code blurInfinity})
+ * @return the refocus filtering result
+ */
+ public Bitmap applyRefocusFilter(DepthOfFieldOptions options) {
+ long startTime = System.currentTimeMillis();
+
+ // Generates {@code rgbdImage} and {@code blurStack}.
+ prepareRefocusFilter(options);
+ Bitmap outputImage = null;
+ // Check which version of RenderScript code is used.
+ switch (mScript) {
+ case f32:
+ RefocusFilterF32 rfFilterF32 = new RefocusFilterF32(renderScript);
+ outputImage =
+ rfFilterF32.compute(rgbdImage, blurStack);
+ break;
+ case d1new:
+ RefocusFilterd1new rfFilterd1new = new RefocusFilterd1new(renderScript);
+ outputImage =
+ rfFilterd1new.compute(rgbdImage, blurStack);
+ break;
+ }
+
+ long endTime = System.currentTimeMillis();
+ float duration = (endTime - startTime);
+ Log.d(TAG, "applyRefocusFilter is finished in " + (duration / 1000.0f)
+ + " seconds");
+
+ return outputImage;
+ }
+
+ /**
+ * A function that computes {@code rgbdImage} and {@code blurStack} from an
+ * instance of {@code DepthOfFieldOptions}.
+ *
+ * @param options an object contains color image, depth map, focal depth, and
+ * the amount of desired blur ({@code blurInfinity}).
+ */
+ private void prepareRefocusFilter(DepthOfFieldOptions options) {
+ blurStack = BlurStack.createFromDepthTransform(
+ options.rgbz.getDepthTransform(), options.focalDepth,
+ options.depthOfField, options.blurInfinity, NUM_BLENDING_LAYERS);
+
+ rgbdImage = options.rgbz.getBitmap();
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/XmpDepthDecode.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/XmpDepthDecode.java
new file mode 100644
index 0000000..ba3d068
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/XmpDepthDecode.java
@@ -0,0 +1,445 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.renderscript.cts.refocus.image.RangeInverseDepthTransform;
+import android.renderscript.cts.refocus.image.RangeLinearDepthTransform;
+import android.util.Log;
+
+import com.adobe.xmp.XMPConst;
+import com.adobe.xmp.XMPException;
+import com.adobe.xmp.XMPIterator;
+import com.adobe.xmp.XMPMeta;
+import com.adobe.xmp.XMPMetaFactory;
+import com.adobe.xmp.properties.XMPPropertyInfo;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class XmpDepthDecode {
+ private static final String TAG = "XmpUtil";
+ private static final String XMP_DEPTHMAP = "http://ns.google.com/photos/1.0/depthmap/";
+ private static final String XMP_FOCUS = "http://ns.google.com/photos/1.0/focus/";
+ private static final String XMP_HEADER = "http://ns.adobe.com/xap/1.0/\0";
+ private static final String XMP_EXTENSION_HEADER =
+ "http://ns.adobe.com/xmp/extension/\0";
+ private static final String XMP_HAS_EXTENSION = "HasExtendedXMP";
+ private static final int XMP_EXTENSION_HEADER_GUID_SIZE =
+ XMP_EXTENSION_HEADER.length() + 32 + 1; // 32 byte GUID + 1 byte null termination.
+ private static final int XMP_EXTENSION_HEADER_OFFSET = 7;
+
+ private static final int M_SOI = 0xd8; // File start marker.
+ private static final int M_APP1 = 0xe1; // Marker for EXIF or XMP.
+ private static final int M_SOS = 0xda; // Image data marker.
+
+ private final String mFormat;
+ private final double mFar;
+ private final double mNear;
+ private final Bitmap mDepthBitmap;
+ private final double mBlurAtInfinity;
+ private final double mFocalDistance;
+ private final double mDepthOfFiled;
+ private final double mFocalPointX;
+ private final double mFocalPointY;
+ private final DepthTransform mDepthTransform;
+
+ public XmpDepthDecode(InputStream is) throws IOException {
+ XMPMeta meta = read(is, false);
+ try {
+ mFormat = meta.getPropertyString(XMP_DEPTHMAP, "GDepth:Format");
+
+ mFar = Double.parseDouble(meta.getPropertyString(XMP_DEPTHMAP, "GDepth:Far"));
+ mNear = Double.parseDouble(meta.getPropertyString(XMP_DEPTHMAP, "GDepth:Near"));
+
+ DepthTransform tDepthTransform = null;
+ String format = meta.getPropertyString(
+ XMP_DEPTHMAP, "GDepth:Format");
+ if (RangeInverseDepthTransform.FORMAT.equals(format)) {
+ tDepthTransform = new RangeInverseDepthTransform((float)mNear, (float)mFar);
+ } else if (RangeLinearDepthTransform.FORMAT.equals(format)) {
+ tDepthTransform = new RangeLinearDepthTransform((float)mNear, (float)mFar);
+ } else {
+ Log.e(TAG, "Unknown GDepth format: " + format);
+ }
+ mDepthTransform = tDepthTransform;
+
+ byte[] data = meta.getPropertyBase64(XMP_DEPTHMAP, "GDepth:Data");
+ mDepthBitmap = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
+
+ mBlurAtInfinity = Double.parseDouble(meta.getPropertyString(XMP_FOCUS, "GFocus:BlurAtInfinity"));
+ mFocalDistance = Double.parseDouble(meta.getPropertyString(XMP_FOCUS, "GFocus:FocalDistance"));
+ mDepthOfFiled = Double.parseDouble(meta.getPropertyString(XMP_FOCUS, "GFocus:DepthOfField"));
+ mFocalPointX = Double.parseDouble(meta.getPropertyString(XMP_FOCUS, "GFocus:FocalPointX"));
+ mFocalPointY = Double.parseDouble(meta.getPropertyString(XMP_FOCUS, "GFocus:FocalPointY"));
+ } catch (XMPException e) {
+ throw new IOException("XMP data missing");
+ }
+ }
+
+ public Bitmap getDepthBitmap() {
+ return mDepthBitmap;
+ }
+
+ public DepthTransform getDepthTransform() { return mDepthTransform; }
+
+ public String getFormat() {
+ return mFormat;
+ }
+
+ public double getFar() {
+ return mFar;
+ }
+
+ public double getNear() {
+ return mNear;
+ }
+
+ public double getBlurAtInfinity() {
+ return mBlurAtInfinity;
+ }
+
+ public double getFocalDistance() {
+ return mFocalDistance;
+ }
+
+ public double getDepthOfField() { return mDepthOfFiled; }
+
+ public double getFocalPointX() {
+ return mFocalPointX;
+ }
+
+ public double getFocalPointY() {
+ return mFocalPointY;
+ }
+
+
+ // JPEG file is composed of many sections and image data. This class is used
+ // to hold the section data from image file.
+ private static class Section {
+ public int marker;
+ public int length;
+ public byte[] data;
+ }
+
+ static XMPMeta read(InputStream is, boolean skipExtendedContent) {
+ List<Section> sections = parse(is, true, skipExtendedContent);
+ if (sections == null) {
+ return null;
+ }
+
+ XMPMeta xmpMeta = parseFirstValidXMPSection(sections);
+ if (xmpMeta == null ||
+ !xmpMeta.doesPropertyExist(XMPConst.NS_XMP_NOTE, XMP_HAS_EXTENSION)) {
+ return xmpMeta;
+ }
+
+ String extensionName = null;
+ try {
+ extensionName = (String) xmpMeta.getProperty(
+ XMPConst.NS_XMP_NOTE, XMP_HAS_EXTENSION).getValue();
+ } catch (XMPException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ if (skipExtendedContent) {
+ if (!checkExtendedSectionExists(sections, extensionName)) {
+ // The main XMP section referenced an extended section that is not present.
+ // This is an error.
+ return null;
+ }
+ return xmpMeta;
+ }
+
+ XMPMeta xmpExtended = parseExtendedXMPSections(sections, extensionName);
+ if (xmpExtended == null) {
+ // The main XMP section referenced an extended section that is not present.
+ // This is an error.
+ return null;
+ }
+
+ // Merge the extended properties into the main one.
+ try {
+ XMPIterator iterator = xmpExtended.iterator();
+ while (true) {
+ XMPPropertyInfo info = (XMPPropertyInfo) iterator.next();
+ if (info.getPath() != null) {
+ xmpMeta.setProperty(info.getNamespace(), info.getPath(),
+ info.getValue(), info.getOptions());
+ }
+ }
+ } catch (Exception e) {
+ // Catch XMPException and NoSuchElementException.
+ }
+ return xmpMeta;
+ }
+
+ /**
+ * Parses the JPEG image file. If readMetaOnly is true, only keeps the EXIF
+ * and XMP sections (with marker M_APP1) and ignore others; otherwise, keep
+ * all sections. The last section with image data will have -1 length.
+ *
+ * @param is Input image data stream
+ * @param readMetaOnly Whether only reads the metadata in jpg
+ * @param skipExtendedContent Whether to skip the content of extended sections
+ * @return The parse result
+ */
+ private static List<Section> parse(InputStream is, boolean readMetaOnly,
+ boolean skipExtendedContent) {
+ List<Section> sections = new ArrayList<Section>();
+ if (is == null) {
+ return sections;
+ }
+
+ try {
+ if (is.read() != 0xff || is.read() != M_SOI) {
+ return sections;
+ }
+ int c;
+ while ((c = is.read()) != -1) {
+ if (c != 0xff) {
+ return sections;
+ }
+ // Skip padding bytes.
+ while ((c = is.read()) == 0xff) {
+ }
+ if (c == -1) {
+ return sections;
+ }
+ int marker = c;
+ if (marker == M_SOS) {
+ // M_SOS indicates the image data will follow and no metadata after
+ // that, so read all data at one time.
+ if (!readMetaOnly) {
+ Section section = new Section();
+ section.marker = marker;
+ section.length = -1;
+ section.data = new byte[is.available()];
+ is.read(section.data, 0, section.data.length);
+ sections.add(section);
+ }
+ return sections;
+ }
+ int lh = is.read();
+ int ll = is.read();
+ if (lh == -1 || ll == -1) {
+ return sections;
+ }
+ int length = lh << 8 | ll;
+ if (!readMetaOnly || marker == M_APP1) {
+ sections.add(readSection(is, length, marker, skipExtendedContent));
+ } else {
+ // Skip this section since all EXIF/XMP meta will be in M_APP1
+ // section.
+ is.skip(length - 2);
+ }
+ }
+ return sections;
+ } catch (IOException e) {
+ System.out.println("Could not parse file." + e);
+ return sections;
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore.
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks whether the byte array has XMP header. The XMP section contains
+ * a fixed length header XMP_HEADER.
+ *
+ * @param data XMP metadata
+ * @param header The header to look for
+ */
+ private static boolean hasHeader(byte[] data, String header) {
+ if (data.length < header.length()) {
+ return false;
+ }
+ try {
+ byte[] buffer = new byte[header.length()];
+ System.arraycopy(data, 0, buffer, 0, header.length());
+ if (new String(buffer, "UTF-8").equals(header)) {
+ return true;
+ }
+ } catch (UnsupportedEncodingException e) {
+ return false;
+ }
+ return false;
+ }
+
+ private static Section readSection(InputStream is, int length,
+ int marker, boolean skipExtendedContent) throws IOException {
+ if (length - 2 < XMP_EXTENSION_HEADER_GUID_SIZE || !skipExtendedContent) {
+ Section section = new Section();
+ section.marker = marker;
+ section.length = length;
+ section.data = new byte[length - 2];
+ is.read(section.data, 0, length - 2);
+ return section;
+ }
+
+ byte[] header = new byte[XMP_EXTENSION_HEADER_GUID_SIZE];
+ is.read(header, 0, header.length);
+
+ if (hasHeader(header, XMP_EXTENSION_HEADER) && skipExtendedContent) {
+ Section section = new Section();
+ section.marker = marker;
+ section.length = header.length + 2;
+ section.data = header;
+ is.skip(length - 2 - header.length);
+ return section;
+ }
+
+ Section section = new Section();
+ section.marker = marker;
+ section.length = length;
+ section.data = new byte[length - 2];
+ System.arraycopy(header, 0, section.data, 0, header.length);
+ is.read(section.data, header.length, length - 2 - header.length);
+ return section;
+ }
+
+ /**
+ * Gets the end of the XMP meta content. If there is no packet wrapper,
+ * return data.length, otherwise return 1 + the position of last '>'
+ * without '?' before it.
+ * Usually the packet wrapper end is "<?xpacket end="w"?> but
+ * javax.xml.parsers.DocumentBuilder fails to parse it in android.
+ *
+ * @param data XMP metadata bytes
+ * @return The end of the XMP metadata content
+ */
+ private static int getXMPContentEnd(byte[] data) {
+ for (int i = data.length - 1; i >= 1; --i) {
+ if (data[i] == '>') {
+ if (data[i - 1] != '?') {
+ return i + 1;
+ }
+ }
+ }
+ // It should not reach here for a valid XMP meta.
+ return data.length;
+ }
+
+ /**
+ * Parses the first valid XMP section. Any other valid XMP section will be
+ * ignored.
+ *
+ * @param sections The list of sections parse
+ * @return The parsed XMPMeta object
+ */
+ private static XMPMeta parseFirstValidXMPSection(List<Section> sections) {
+ for (Section section : sections) {
+ if (hasHeader(section.data, XMP_HEADER)) {
+ int end = getXMPContentEnd(section.data);
+ byte[] buffer = new byte[end - XMP_HEADER.length()];
+ System.arraycopy(
+ section.data, XMP_HEADER.length(), buffer, 0, buffer.length);
+ try {
+ XMPMeta result = XMPMetaFactory.parseFromBuffer(buffer);
+ return result;
+ } catch (XMPException e) {
+ System.out.println("XMP parse error " + e);
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks there is an extended section with the given name.
+ *
+ * @param sections The list of sections to parse
+ * @param sectionName The name of the extended sections
+ * @return Whether there is an extended section with the given name
+ */
+ private static boolean checkExtendedSectionExists(List<Section> sections,
+ String sectionName) {
+ String extendedHeader = XMP_EXTENSION_HEADER + sectionName + "\0";
+ for (Section section : sections) {
+ if (hasHeader(section.data, extendedHeader)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Parses the extended XMP sections with the given name. All other sections
+ * will be ignored.
+ *
+ * @param sections The list of sections to parse
+ * @param sectionName The name of the extended sections
+ * @return The parsed XMPMeta object
+ */
+ private static XMPMeta parseExtendedXMPSections(List<Section> sections,
+ String sectionName) {
+ String extendedHeader = XMP_EXTENSION_HEADER + sectionName + "\0";
+
+ // Compute the size of the buffer to parse the extended sections.
+ List<Section> xmpSections = new ArrayList<Section>();
+ List<Integer> xmpStartOffset = new ArrayList<Integer>();
+ List<Integer> xmpEndOffset = new ArrayList<Integer>();
+ int bufferSize = 0;
+ for (Section section : sections) {
+ if (hasHeader(section.data, extendedHeader)) {
+ int startOffset = extendedHeader.length() + XMP_EXTENSION_HEADER_OFFSET;
+ int endOffset = section.data.length;
+ bufferSize += Math.max(0, section.data.length - startOffset);
+ xmpSections.add(section);
+ xmpStartOffset.add(startOffset);
+ xmpEndOffset.add(endOffset);
+ }
+ }
+ if (bufferSize == 0) {
+ return null;
+ }
+
+ // Copy all the relevant sections' data into a buffer.
+ byte buffer[] = new byte[bufferSize];
+ int offset = 0;
+ for (int i = 0; i < xmpSections.size(); ++i) {
+ Section section = xmpSections.get(i);
+ int startOffset = xmpStartOffset.get(i);
+ int endOffset = xmpEndOffset.get(i);
+ int length = endOffset - startOffset;
+ System.arraycopy(
+ section.data, startOffset, buffer, offset, length);
+ offset += length;
+ }
+
+ XMPMeta xmpExtended = null;
+ try {
+ xmpExtended = XMPMetaFactory.parseFromBuffer(buffer);
+ } catch (XMPException e) {
+ System.out.println("Extended XMP parse error " + e);
+ return null;
+ }
+ return xmpExtended;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response.rsh
new file mode 100644
index 0000000..87cf688
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response.rsh
@@ -0,0 +1,130 @@
+#ifndef CAMERA_RESPONSE_RSH
+#define CAMERA_RESPONSE_RSH
+
+// Adapt //depot/google3/geo/lightfield/refocus/image/camera_response.h|cc to
+// Render Script.
+//
+// Implementation of a three-parameter Camera Response Function as described in:
+//
+// Comparametric Equations with Practical Applications
+// in Quantigraphic Image Processing,
+// by Steve Mann, IEEE TOIP 2000.
+//
+// The difference here is that we use a normalized model such
+// that f(0) = 0 and f(1) = 1. The function and its inverse is
+// given with respect to parameters a,b,c as:
+//
+// f(q) = ((e^b + 1) * q^a / (e^b * q^a + 1))^c
+// f^-1(q) = (x^(1/c) / (e^b - e^b * x^(1/c) + 1))^(1/a)
+//
+// The typical work flow is to first remove the response from a photograph,
+// do some computation in the radiance space, then re-apply the response to
+// the processed photo.
+
+// Quantize a float in [0,1] using an integer in [0,kLUTLength-1].
+static const int kLUTLength = 256;
+// Default parameters of the camera response function.
+static const float kDefaultA = 2.0f;
+static const float kDefaultB = 4.0f;
+static const float kDefaultC = 3.0f;
+
+rs_allocation g_lut_apply_crf_float;
+rs_allocation g_lut_remove_crf_float;
+
+typedef struct CameraResponse {
+ float a;
+ float b;
+ float c;
+ float lut_apply_crf_float[kLUTLength + 1];
+ float lut_remove_crf_float[kLUTLength + 1];
+ int lut_apply_crf_int[kLUTLength];
+ int lut_remove_crf_int[kLUTLength];
+} CameraResponse_t;
+
+static inline float ApplyCRF(float v, const CameraResponse_t* camera_response) {
+ const float pow_va = pow(v, camera_response->a);
+ const float exp_b = exp(camera_response->b);
+ const float x1 = (exp_b + 1.0f) * pow_va;
+ const float x2 = exp_b * pow_va + 1.0f;
+ return pow(x1 / x2, camera_response->c);
+}
+
+static inline float RemoveCRF(float v,
+ const CameraResponse_t* camera_response) {
+ const float pow_vc = pow(v, 1.0f / camera_response->c);
+ const float x2 = exp(camera_response->b) * (1.0f - pow_vc) + 1.0f;
+ return pow(pow_vc / x2, 1.0f / camera_response->a);
+}
+
+static inline float ApplyCRFdefault(float v) {
+ const float pow_va = pow(v, kDefaultA);
+ const float exp_b = exp(kDefaultB);
+ const float x1 = (exp_b + 1.0f) * pow_va;
+ const float x2 = exp_b * pow_va + 1.0f;
+ return pow(x1 / x2, kDefaultC);
+}
+
+static inline float RemoveCRFdefault(float v) {
+ const float pow_vc = pow(v, 1.0f / kDefaultC);
+ const float x2 = exp(kDefaultB) * (1.0f - pow_vc) + 1.0f;
+ return pow(pow_vc / x2, 1.0f / kDefaultA);
+}
+
+static inline void ComputeLUTs(CameraResponse_t* camera_response) {
+ for (int i = 0; i < kLUTLength; ++i) {
+ const float value = i / (float)(kLUTLength - 1);
+
+ const float y = ApplyCRF(value, camera_response);
+ camera_response->lut_apply_crf_float[i] = y;
+ camera_response->lut_apply_crf_int[i] = round((kLUTLength - 1) * y);
+
+ const float x = RemoveCRF(value, camera_response);
+ camera_response->lut_remove_crf_float[i] = x;
+ camera_response->lut_remove_crf_int[i] = round((kLUTLength - 1) * x);
+ }
+
+ // Add a boundary to correctly deal with the max value in ApplyLUT.
+ camera_response->lut_apply_crf_float[kLUTLength] =
+ camera_response->lut_apply_crf_float[kLUTLength - 1];
+ camera_response->lut_remove_crf_float[kLUTLength] =
+ camera_response->lut_remove_crf_float[kLUTLength - 1];
+}
+
+static inline float ApplyLUT_Float(float value, float lut[kLUTLength + 1]) {
+ const float scaled_value = (kLUTLength - 1) * value;
+ const int pos = (int)(scaled_value);
+ const float delta = scaled_value - pos;
+ return lut[pos] + delta * (lut[pos + 1] - lut[pos]);
+}
+
+static inline float ApplyLUT_FloatAlloc(float value) {
+ const float scaled_value = (kLUTLength - 1) * value;
+ const int pos = (int)(scaled_value);
+ const float delta = scaled_value - pos;
+ float valPos = rsGetElementAt_float(g_lut_apply_crf_float, pos);
+ float valPosPlus = rsGetElementAt_float(g_lut_apply_crf_float, pos+1);
+ return valPos + delta * (valPosPlus - valPos);
+}
+
+static inline float ApplyLUT_FloatRemoveAlloc(float value) {
+ const float scaled_value = (kLUTLength - 1) * value;
+ const int pos = (int)(scaled_value);
+ const float delta = scaled_value - pos;
+ float valPos = rsGetElementAt_float(g_lut_remove_crf_float, pos);
+ float valPosPlus = rsGetElementAt_float(g_lut_remove_crf_float, pos+1);
+ return valPos + delta * (valPosPlus - valPos);
+}
+
+static inline int ApplyLUT_Int(int value, int lut[kLUTLength]) {
+ return lut[value];
+}
+
+static inline void InitializeDefaultCameraResponse(
+ CameraResponse_t* camera_response) {
+ camera_response->a = kDefaultA;
+ camera_response->b = kDefaultB;
+ camera_response->c = kDefaultC;
+ ComputeLUTs(camera_response);
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response_fast.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response_fast.rsh
new file mode 100644
index 0000000..d664fd2
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/camera_response_fast.rsh
@@ -0,0 +1,69 @@
+#ifndef CAMERA_RESPONSE_FAST_RSH
+#define CAMERA_RESPONSE_FAST_RSH
+
+// Adapt //depot/google3/geo/lightfield/refocus/image/camera_response.h|cc to
+// Render Script.
+//
+// Implementation of a three-parameter Camera Response Function as described in:
+//
+// Comparametric Equations with Practical Applications
+// in Quantigraphic Image Processing,
+// by Steve Mann, IEEE TOIP 2000.
+//
+// The difference here is that we use a normalized model such
+// that f(0) = 0 and f(1) = 1. The function and its inverse is
+// given with respect to parameters a,b,c as:
+//
+// f(q) = ((e^b + 1) * q^a / (e^b * q^a + 1))^c
+// f^-1(q) = (x^(1/c) / (e^b - e^b * x^(1/c) + 1))^(1/a)
+//
+// The typical work flow is to first remove the response from a photograph,
+// do some computation in the radiance space, then re-apply the response to
+// the processed photo.
+
+// Quantize a float in [0,1] using an integer in [0,kLUTLength-1].
+static const int kLUTLength = 256;
+// Default parameters of the camera response function.
+static const float kDefaultA = 2.0f;
+static const float kDefaultB = 4.0f;
+static const float kDefaultC = 3.0f;
+
+rs_allocation g_lut_apply_crf_float;
+rs_allocation g_lut_remove_crf_float;
+
+
+
+static inline float ApplyCRFdefault(float v) {
+ const float pow_va = pow(v, kDefaultA);
+ const float exp_b = exp(kDefaultB);
+ const float x1 = (exp_b + 1.0f) * pow_va;
+ const float x2 = exp_b * pow_va + 1.0f;
+ return pow(x1 / x2, kDefaultC);
+}
+
+static inline float RemoveCRFdefault(float v) {
+ const float pow_vc = pow(v, 1.0f / kDefaultC);
+ const float x2 = exp(kDefaultB) * (1.0f - pow_vc) + 1.0f;
+ return pow(pow_vc / x2, 1.0f / kDefaultA);
+}
+
+
+static inline float ApplyLUT_FloatAlloc(float value) {
+ const float scaled_value = (kLUTLength - 1) * value;
+ const int pos = (int)(scaled_value);
+ const float delta = scaled_value - pos;
+ float valPos = rsGetElementAt_float(g_lut_apply_crf_float, pos);
+ float valPosPlus = rsGetElementAt_float(g_lut_apply_crf_float, pos+1);
+ return valPos + delta * (valPosPlus - valPos);
+}
+
+static inline float ApplyLUT_FloatRemoveAlloc(float value) {
+ const float scaled_value = (kLUTLength - 1) * value;
+ const int pos = (int)(scaled_value);
+ const float delta = scaled_value - pos;
+ float valPos = rsGetElementAt_float(g_lut_remove_crf_float, pos);
+ float valPosPlus = rsGetElementAt_float(g_lut_remove_crf_float, pos+1);
+ return valPos + delta * (valPosPlus - valPos);
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/ImageBuffersForRenderScriptd1new.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/ImageBuffersForRenderScriptd1new.java
new file mode 100644
index 0000000..ac67ef6
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/ImageBuffersForRenderScriptd1new.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.d1new;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.refocus.ImageBuffersForRenderScript;
+import android.renderscript.cts.refocus.LayerInfo;
+import android.renderscript.cts.refocus.ScriptC_layered_filter_fast_d1new;
+import android.util.Log;
+
+/**
+ * A class that manages the image buffers that interface between Java and Render
+ * Script. These buffers are specialized for float32 pixel representation.
+ */
+public class ImageBuffersForRenderScriptd1new extends
+ ImageBuffersForRenderScript {
+ /**
+ * SharpImage, FuzzyImage, and integralImage that are bound with memory in
+ * Render Script for layered filtering.
+ * Global allocation for images and meta data that are bound with memory in Render Script
+ *
+ */
+ private static final String myTAG = "RefocusFilterd1new";
+ public Allocation sharpRGBAAllocation;
+ public Allocation fuzzyRGBAAllocation;
+ public Allocation integralRGBAAllocation;
+
+ public Allocation sharpActualDepthAllocation;
+ public Allocation sharpDilatedDepthAllocation;
+ public Allocation sharpActiveAllocation;
+ public Allocation sharpMatteAllocation;
+
+ /**
+ * A constructor that allocates memory buffers in Java and binds the buffers
+ * with the global pointers in the Render Script.
+ *
+ * @param image an input (padded) RGBD image
+ * @param renderScript a RenderScript object that manages the {@code Context}
+ * in Java
+ * @param scriptC a RenderScript object that manages the filtering kernel
+ * functions in .rs file
+ */
+ public ImageBuffersForRenderScriptd1new(Bitmap image, int margin,
+ RenderScript renderScript, ScriptC_layered_filter_fast_d1new scriptC) {
+ super(image, margin, renderScript);
+ sharpRGBAAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ sharpActualDepthAllocation = Allocation.createSized(
+ renderScript, Element.U8(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ sharpDilatedDepthAllocation = Allocation.createSized(
+ renderScript, Element.U8(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ sharpActiveAllocation = Allocation.createSized(
+ renderScript, Element.U8(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ sharpMatteAllocation = Allocation.createSized(
+ renderScript, Element.U8(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ fuzzyRGBAAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ imageWidthPadded * imageHeightPadded);
+ integralRGBAAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ imageWidthPadded * imageHeightPadded);
+
+ scriptC.set_g_sharp_RGBA(sharpRGBAAllocation);
+ scriptC.set_g_fuzzy_RGBA(fuzzyRGBAAllocation);
+ scriptC.set_g_integral_RGBA(integralRGBAAllocation);
+
+ scriptC.set_g_sharp_actual_depth(sharpActualDepthAllocation);
+ scriptC.set_g_sharp_active(sharpActiveAllocation);
+ scriptC.set_g_sharp_matte(sharpMatteAllocation);
+ scriptC.set_g_sharp_dilated_depth(sharpDilatedDepthAllocation);
+
+ }
+
+ /**
+ * A function that passes global parameters from Java to Render Script and
+ * sets up the input image.
+ *
+ * @param focalLayer a layer for the depth value interval that has zero blur.
+ * @param scriptC a RenderScript object that manages filtering kernels and
+ * global variables in .rs file
+ */
+ public void initializeRenderScript(LayerInfo focalLayer,
+ ScriptC_layered_filter_fast_d1new scriptC) {
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.invoke_InitializeFast(imageWidthPadded, imageHeightPadded,
+ paddedMargin, focalLayer.frontDepth, focalLayer.backDepth);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "Initialize: " + (endnow - startnow) + " ns");
+ // At this point, {@code inAllocation} contains input RGBD image in Java.
+ // {@code g_sharp_image} is a global pointer that points the focus image in
+ // Render Script. The following function copies {@code inAllocation} in
+ // Java to {@code g_sharp_image) in Render Script.
+ startnow = System.nanoTime();
+ scriptC.forEach_UnpackInputImage(inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "UnpackInputImage: " + (endnow - startnow) + " ns");
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/KernelDataForRenderScriptd1new.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/KernelDataForRenderScriptd1new.java
new file mode 100644
index 0000000..babd257
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/KernelDataForRenderScriptd1new.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.d1new;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.refocus.BlurStack;
+import android.renderscript.cts.refocus.KernelDataForRenderScript;
+
+import java.util.Arrays;
+
+/**
+ * A class that manages the blur kernel matrices of a blending layer that
+ * interface between Java and Render Script.
+ */
+public class KernelDataForRenderScriptd1new extends KernelDataForRenderScript {
+ /**
+ * A stack of blur kernel matrices packed into a continuous memory buffer.
+ */
+ float[] kernelStack;
+
+ /**
+ * The minimum blur disk in the stack.
+ */
+ float minDiskRadius;
+
+ /**
+ * An RenderScript Allocation for kernelStack.
+ */
+ Allocation stackAllocation;
+
+ /**
+ * Initializes {@code kernelStack} and {@code kernelInfo}.
+ *
+ * @param targetLayer the index of a target layer
+ * @param blurStack an instance of {@code BlurStack}
+ * @param renderScript an instance of {@code RenderScript}
+ */
+ public KernelDataForRenderScriptd1new(int targetLayer, BlurStack blurStack,
+ RenderScript renderScript) {
+ super(targetLayer, blurStack, renderScript);
+ // stackLength is set in super.
+
+ kernelStack = new float[stackLength];
+ int numDepths = blurStack.getNumDepths(targetLayer);
+ minDiskRadius = BlurStack.getMaxDiskRadius();
+ for (int m = 0; m < numDepths; ++m) {
+ int depth = blurStack.getDepth(targetLayer, m);
+ float diskRadius = blurStack.getDiskRadius(depth);
+ float[] kernelMatrix = getKernel(diskRadius);
+ //System.arraycopy(kernelMatrix, 0, kernelStack, kernelInfo.get_offset(m),
+ // kernelMatrix.length);
+ System.arraycopy(kernelMatrix, 0, kernelStack, (int)infoArray[4*m],
+ kernelMatrix.length);
+ minDiskRadius = Math.min(minDiskRadius, diskRadius);
+ }
+
+ stackAllocation = Allocation.createSized(renderScript,
+ Element.F32(renderScript), kernelStack.length);
+ stackAllocation.copyFrom(kernelStack);
+ }
+
+ /**
+ * Returns the kernel matrix of a depth level.
+ *
+ * @param diskRadius disk radius of the kernel.
+ * @return the kernel matrix of the disk radius.
+ */
+ public float[] getKernel(float diskRadius) {
+ int kernelRadius = computeKernelRadiusFromDiskRadius(diskRadius);
+ return generateDiskKernelArray(diskRadius, kernelRadius);
+ }
+
+ /**
+ * Generates a blur kernel matrix for a blur disk with radius
+ * {@code diskRadius}.
+ *
+ * @param diskRadius radius of blur disk
+ * @param kernelRadius radius of blur kernel matrix
+ * @return a kernel matrix represented as an array
+ */
+ private static float[] generateDiskKernelArray(float diskRadius,
+ int kernelRadius) {
+ int kernelDim = 2 * kernelRadius + 1;
+ int kernelLength = kernelDim * kernelDim;
+
+ float[] kernel = new float[kernelLength];
+ Arrays.fill(kernel, 0);
+
+ // Generates {@code NUM_SUB_PIXELS*NUM_SUB_PIXELS} sub-pixel shifts {@code
+ // (dx,dy)} uniformly within [-0.5,0.5]*[-0.5,0.5].
+ // For each shift, tests whether or not the shifted pixel is within the
+ // disc and accumulates the count.
+ float diskRadius2 = diskRadius * diskRadius;
+ float dy0 = -0.5f + 1.0f / (2 * getNumSubPixels());
+ float dx0 = -0.5f + 1.0f / (2 * getNumSubPixels());
+
+ float sumKernelValues = 0;
+ for (int v = 0; v < getNumSubPixels(); ++v) {
+ float dy = dy0 + (float) v / (float) getNumSubPixels();
+ for (int u = 0; u < getNumSubPixels(); ++u) {
+ float dx = dx0 + (float) u / (float) getNumSubPixels();
+ for (int y = 0; y < kernelDim; ++y) {
+ float yf = y - kernelRadius + dy;
+ for (int x = 0; x < kernelDim; ++x) {
+ float xf = x - kernelRadius + dx;
+ if (yf * yf + xf * xf <= diskRadius2) {
+ kernel[y * kernelDim + x] += 1;
+ sumKernelValues += 1;
+ }
+ }
+ }
+ }
+ }
+
+ // Normalizes kernel elements such that they sum up to 1.
+ for (int n = 0; n < kernelLength; ++n) {
+ kernel[n] /= sumKernelValues;
+ }
+
+ return kernel;
+ }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/RefocusFilterd1new.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/RefocusFilterd1new.java
new file mode 100644
index 0000000..3942982
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/d1new/RefocusFilterd1new.java
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.d1new;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+
+import android.renderscript.Script;
+import android.renderscript.cts.refocus.BlurStack;
+import android.renderscript.cts.refocus.KernelDataForRenderScript;
+import android.renderscript.cts.refocus.LayerInfo;
+import android.renderscript.cts.refocus.MediaStoreSaver;
+import android.renderscript.cts.refocus.RefocusFilter;
+import android.renderscript.cts.refocus.ScriptC_layered_filter_fast_d1new;
+import android.util.Log;
+
+/**
+ * An accelerated implementation of RefocusFilter using float32 as pixel
+ * representation. The corresponding RenderScript class is
+ * ScriptC_layered_filter_Fast. Integral image is used for the speedup.
+ *
+ * Example Usage:
+ *
+ * {@code RenderScript renderScript = RenderScript.create(context);}
+ * {@code RefocusFilterd1new rfFilter = new RefocusFilterd1new(renderScript);}
+ * {@code ProgressCallback progress;}
+ * {@code Bitmap result = rfFilter.compute(rgbdImage, blurStack, progress);}
+ */
+public class RefocusFilterd1new extends
+ RefocusFilter<ScriptC_layered_filter_fast_d1new> {
+ private static final String myTAG = "RefocusFilterd1new";
+ private static final boolean ENABLE_FAST_FILTER = true;
+ private static final float MIN_DISC_RADIUS_FOR_FAST_FILTER = 3;
+ boolean useFastFilterForCurrentLayer = false;
+ ImageBuffersForRenderScriptd1new buffers;
+
+ public RefocusFilterd1new(RenderScript rs) {
+ super(rs);
+ }
+
+ @Override
+ protected void initializeScriptAndBuffers(Bitmap inputImage,
+ LayerInfo focalLayer) {
+ scriptC = new ScriptC_layered_filter_fast_d1new(renderScript);
+
+ // Allocates, binds, and initializes buffers that interface between Java
+ // and Render Script.
+ // + 1 is for the boundary case of using integral image.
+ KernelDataForRenderScript.setUseNewRS(true);
+ int margin = KernelDataForRenderScript.getMaxKernelRadius() + 1;
+ buffers = new ImageBuffersForRenderScriptd1new(inputImage, margin,
+ renderScript, scriptC);
+ buffers.initializeRenderScript(focalLayer, scriptC);
+ }
+
+ @Override
+ protected Bitmap extractResultImage() {
+ // Extracts the result from .rs file to {@code buffers.outputImage} in Java.
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_PackOutputImage(buffers.outAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "PackOutputImage: "+(endnow - startnow)+ " ns" );
+
+ buffers.outAllocation.copyTo(buffers.outputImage);
+ return buffers.outputImage;
+ }
+
+ /*
+ * Utility Method to extract intermediatory result
+ */
+ private void extractSharpImage(String name) {
+
+ Bitmap mBitmap = Bitmap.createBitmap(buffers.inputImage.getWidth(),
+ buffers.inputImage.getHeight(), Bitmap.Config.ARGB_8888);
+ Allocation mAllocation = Allocation.createFromBitmap(renderScript, mBitmap);
+ scriptC.forEach_PackSharpImage(mAllocation);
+
+ mAllocation.copyTo(mBitmap);
+ MediaStoreSaver.savePNG(mBitmap, "sharpd1new", name, renderScript.getApplicationContext());
+ }
+ /*
+ * Utility Method to extract intermediatory result
+ */
+ private void extractFuzzyImage(String name) {
+
+ Bitmap mBitmap = Bitmap.createBitmap(buffers.inputImage.getWidth(),
+ buffers.inputImage.getHeight(), Bitmap.Config.ARGB_8888);
+ Allocation mAllocation = Allocation.createFromBitmap(renderScript, mBitmap);
+ scriptC.forEach_PackFuzzyImage(mAllocation);
+
+ mAllocation.copyTo(mBitmap);
+ MediaStoreSaver.savePNG(mBitmap, "fuzzyd1new", name, renderScript.getApplicationContext());
+ }
+
+ @Override
+ protected void setTargetLayer(LayerInfo layerInfo) {
+ scriptC.invoke_SetTargetLayer(layerInfo.frontDepth, layerInfo.backDepth);
+ }
+
+ @Override
+ protected void setBlendInfo(int dilationRadius) {
+ scriptC.invoke_SetBlendInfo(dilationRadius);
+ }
+
+ @Override
+ protected void setKernelData(int targetLayer, BlurStack blurStack) {
+ KernelDataForRenderScriptd1new kernelData =
+ new KernelDataForRenderScriptd1new(targetLayer, blurStack, renderScript);
+
+ if (ENABLE_FAST_FILTER
+ && kernelData.minDiskRadius > MIN_DISC_RADIUS_FOR_FAST_FILTER) {
+ useFastFilterForCurrentLayer = true;
+ } else {
+ useFastFilterForCurrentLayer = false;
+ }
+ scriptC.set_g_kernel_stack(kernelData.stackAllocation);
+ scriptC.set_galloc_kernel_info(kernelData.infoAllocation);
+ }
+
+ @Override
+ protected void computeLayerMatteBehindFocalDepth() {
+ // Marks active pixels (pixels that are on this target layer);
+ // Marks adjacent pixels that are close enough to active pixels;
+ long startnow;
+ long endnow;
+
+ startnow = System.nanoTime();
+ //scriptC.forEach_MarkLayerMask(buffers.inAllocation);
+ // Pass sharp meta allocation directly into the kernel
+ scriptC.forEach_MarkLayerMaskPassInput(buffers.sharpActualDepthAllocation, buffers.sharpDilatedDepthAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "MarkLayerMask: "+(endnow - startnow)+ " ns" );
+
+ startnow = System.nanoTime();
+ //scriptC.forEach_ComputeLayerMatteBehindFocalDepth(buffers.inAllocation);
+ // Pass g_sharp_meta into kernel and get updated g_sharp_meta
+ scriptC.forEach_ComputeLayerMatteBehindFocalDepthPassInput(buffers.sharpDilatedDepthAllocation, buffers.sharpDilatedDepthAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeLayerMatteBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+ }
+
+ @Override
+ protected void filterLayerBehindFocalDepth() {
+ // Filters the target layer and saves the result to {@code g_accum_map} in
+ // .rs file.
+ long startnow;
+ long endnow;
+
+ if (useFastFilterForCurrentLayer) {
+ scriptC.invoke_SetUseIntegralImage(1);
+ Script.LaunchOptions launchOptions = new Script.LaunchOptions();
+ launchOptions.setX(0, 1);
+ launchOptions.setY(0, buffers.inputImage.getHeight());
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeIntegralImageForLayerBehindFocalDepth(
+ buffers.inAllocation, launchOptions);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeIntegralImageForLayerBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+ } else {
+ scriptC.invoke_SetUseIntegralImage(0);
+ }
+
+ startnow = System.nanoTime();
+ //scriptC.forEach_FilterLayerBehindFocalDepth(buffers.inAllocation);
+ // Pass g_fuzzy_RGBA into kernel and get g_fuzzy_RGBA as output
+ scriptC.forEach_FilterLayerBehindFocalDepthPassInput(buffers.fuzzyRGBAAllocation, buffers.fuzzyRGBAAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "FilterLayerBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+ //extractFuzzyImage("fuzzy_behind");
+ //extractSharpImage("sharp_behind");
+ }
+
+ @Override
+ protected void updateSharpImageUsingFuzzyImage() {
+ long startnow;
+ long endnow;
+
+ startnow = System.nanoTime();
+
+ //scriptC.forEach_UpdateSharpImageUsingFuzzyImage(buffers.inAllocation);
+ // Pass input and output version of UpdateSharpImageUsingFuzzyImage
+ scriptC.forEach_UpdateSharpUsingFuzzyPassInput(buffers.sharpDilatedDepthAllocation, buffers.sharpDilatedDepthAllocation);
+
+ endnow = System.nanoTime();
+ Log.d(myTAG, "updateSharpImageUsingFuzzyImage: "+(endnow - startnow)+ " ns" );
+ //extractSharpImage("sharp_update");
+ }
+
+ @Override
+ protected void computeLayerMatteInFrontOfFocalDepth() {
+ // Marks active pixels (pixels that are on this target layer);
+ // Marks adjacent pixels that are close enough to active pixels;
+ long startnow;
+ long endnow;
+
+ startnow = System.nanoTime();
+ //scriptC.forEach_MarkLayerMask(buffers.inAllocation);
+ // Pass sharp meta allocation directly into the kernel
+ scriptC.forEach_MarkLayerMaskPassInput(buffers.sharpActualDepthAllocation, buffers.sharpDilatedDepthAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "MarkLayerMask: "+(endnow - startnow)+ " ns" );
+
+ startnow = System.nanoTime();
+ //scriptC.forEach_ComputeLayerMatteInFrontOfFocalDepth(buffers.inAllocation);
+ // Pass g_sharp_meta and g_fuzzy_RGBA directly into the kernel
+ scriptC.forEach_ComputeLayerMatteInFrontOfFocalDepthPassInput(buffers.sharpDilatedDepthAllocation, buffers.sharpDilatedDepthAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeLayerMatteInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+ }
+
+ @Override
+ protected void filterLayerInFrontOfFocalDepth() {
+ // Filters the target layer and accumulates the result to {@code
+ // g_accum_map} in .rs file.
+ long startnow;
+ long endnow;
+ if (useFastFilterForCurrentLayer) {
+ scriptC.invoke_SetUseIntegralImage(1);
+ Script.LaunchOptions launchOptions = new Script.LaunchOptions();
+ launchOptions.setX(0, 1);
+ launchOptions.setY(0, buffers.inputImage.getHeight());
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeIntegralImageForLayerInFrontOfFocalDepth(
+ buffers.inAllocation, launchOptions);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeIntegralImageForLayerInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+ } else {
+ scriptC.invoke_SetUseIntegralImage(0);
+ }
+ startnow = System.nanoTime();
+ //scriptC.forEach_FilterLayerInFrontOfFocalDepth(buffers.inAllocation);
+ // Pass g_sharp_dilated_depth into kernel and get g_fuzzy_RGBA as output
+ scriptC.forEach_FilterLayerInFrontOfFocalDepthPassInput(buffers.sharpDilatedDepthAllocation, buffers.sharpDilatedDepthAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "FilterLayerInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+
+ //extractFuzzyImage("fuzzy_front");
+ //extractSharpImage("sharp_front");
+ }
+
+ @Override
+ protected void finalizeFuzzyImageUsingSharpImage() {
+ // Blends {@code g_accum_map} and {@code g_focus_map} in .rs file.
+ // Saves the result in {@code g_accum_map}.
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_FinalizeFuzzyImageUsingSharpImage(buffers.inAllocation);
+ //scriptC.forEach_FinalizeFuzzyImageUsingSharpImagePassInput(buffers.sharpActualDepthAllocation, buffers.fuzzyRGBAAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "finalizeFuzzyImageUsingSharpImage: "+(endnow - startnow)+ " ns" );
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/ImageBuffersForRenderScriptF32.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/ImageBuffersForRenderScriptF32.java
new file mode 100644
index 0000000..53e6e55
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/ImageBuffersForRenderScriptF32.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.f32;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.refocus.ImageBuffersForRenderScript;
+import android.renderscript.cts.refocus.LayerInfo;
+import android.renderscript.cts.refocus.ScriptC_layered_filter_fast_f32;
+
+import android.util.Log;
+
+/**
+ * A class that manages the image buffers that interface between Java and Render
+ * Script. These buffers are specialized for float32 pixel representation.
+ */
+public class ImageBuffersForRenderScriptF32 extends
+ ImageBuffersForRenderScript {
+ /**
+ * SharpImage, FuzzyImage, and integralImage that are bound with memory in
+ * Render Script for layered filtering.
+ */
+ private static final String myTAG = "RefocusFilterF32";
+ public Allocation sharpImageAllocation;
+ public Allocation fuzzyImageAllocation;
+ public Allocation integralImageAllocation;
+
+ /**
+ * A constructor that allocates memory buffers in Java and binds the buffers
+ * with the global pointers in the Render Script.
+ *
+ * @param image an input (padded) RGBD image
+ * @param renderScript a RenderScript object that manages the {@code Context}
+ * in Java
+ * @param scriptC a RenderScript object that manages the filtering kernel
+ * functions in .rs file
+ */
+ public ImageBuffersForRenderScriptF32(Bitmap image, int margin,
+ RenderScript renderScript, ScriptC_layered_filter_fast_f32 scriptC) {
+ super(image, margin, renderScript);
+
+ sharpImageAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ imageWidthPadded * imageHeightPadded);
+
+ fuzzyImageAllocation = Allocation.createSized(
+ renderScript, Element.F32_4(renderScript),
+ imageWidthPadded * imageHeightPadded);
+
+ integralImageAllocation = Allocation.createSized(renderScript,
+ Element.F32_4(renderScript), imageWidthPadded * imageHeightPadded);
+
+ scriptC.bind_g_sharp_image_buffer(sharpImageAllocation);
+ scriptC.bind_g_fuzzy_image_buffer(fuzzyImageAllocation);
+ scriptC.bind_g_integral_image_buffer(integralImageAllocation);
+ }
+
+ /**
+ * A function that passes global parameters from Java to Render Script and
+ * sets up the input image.
+ *
+ * @param focalLayer a layer for the depth value interval that has zero blur.
+ * @param scriptC a RenderScript object that manages filtering kernels and
+ * global variables in .rs file
+ */
+ public void initializeRenderScript(LayerInfo focalLayer,
+ ScriptC_layered_filter_fast_f32 scriptC) {
+ long startnow;
+ long endnow;
+
+ startnow = System.nanoTime();
+ scriptC.invoke_InitializeF32(imageWidthPadded, imageHeightPadded,
+ paddedMargin, focalLayer.frontDepth, focalLayer.backDepth);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "Initialize: " + (endnow - startnow) + " ns");
+ // At this point, {@code inAllocation} contains input RGBD image in Java.
+ // {@code g_sharp_image} is a global pointer that points the focus image in
+ // Render Script. The following function copies {@code inAllocation} in
+ // Java to {@code g_sharp_image) in Render Script.
+ startnow = System.nanoTime();
+ scriptC.forEach_UnpackInputImage(inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "UnpackInputImage: " + (endnow - startnow) + " ns");
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/KernelDataForRenderScriptF32.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/KernelDataForRenderScriptF32.java
new file mode 100644
index 0000000..b2e99f0
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/KernelDataForRenderScriptF32.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.f32;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.cts.refocus.BlurStack;
+import android.renderscript.cts.refocus.KernelDataForRenderScript;
+
+import java.util.Arrays;
+
+/**
+ * A class that manages the blur kernel matrices of a blending layer that
+ * interface between Java and Render Script.
+ */
+public class KernelDataForRenderScriptF32 extends KernelDataForRenderScript {
+ /**
+ * A stack of blur kernel matrices packed into a continuous memory buffer.
+ */
+ float[] kernelStack;
+
+ /**
+ * The minimum blur disk in the stack.
+ */
+ float minDiskRadius;
+
+ /**
+ * An RenderScript Allocation for kernelStack.
+ */
+ Allocation stackAllocation;
+
+ /**
+ * Initializes {@code kernelStack} and {@code kernelInfo}.
+ *
+ * @param targetLayer the index of a target layer
+ * @param blurStack an instance of {@code BlurStack}
+ * @param renderScript an instance of {@code RenderScript}
+ */
+ public KernelDataForRenderScriptF32(int targetLayer, BlurStack blurStack,
+ RenderScript renderScript) {
+ super(targetLayer, blurStack, renderScript);
+ // stackLength is set in super.
+
+ kernelStack = new float[stackLength];
+ int numDepths = blurStack.getNumDepths(targetLayer);
+ minDiskRadius = BlurStack.getMaxDiskRadius();
+ for (int m = 0; m < numDepths; ++m) {
+ int depth = blurStack.getDepth(targetLayer, m);
+ float diskRadius = blurStack.getDiskRadius(depth);
+ float[] kernelMatrix = getKernel(diskRadius);
+ System.arraycopy(kernelMatrix, 0, kernelStack, kernelInfo.get_offset(m),
+ kernelMatrix.length);
+ minDiskRadius = Math.min(minDiskRadius, diskRadius);
+ }
+
+ stackAllocation = Allocation.createSized(renderScript,
+ Element.F32(renderScript), kernelStack.length);
+ stackAllocation.copyFrom(kernelStack);
+ }
+
+ /**
+ * Returns the kernel matrix of a depth level.
+ *
+ * @param diskRadius disk radius of the kernel.
+ * @return the kernel matrix of the disk radius.
+ */
+ public float[] getKernel(float diskRadius) {
+ int kernelRadius = computeKernelRadiusFromDiskRadius(diskRadius);
+ return generateDiskKernelArray(diskRadius, kernelRadius);
+ }
+
+ /**
+ * Generates a blur kernel matrix for a blur disk with radius
+ * {@code diskRadius}.
+ *
+ * @param diskRadius radius of blur disk
+ * @param kernelRadius radius of blur kernel matrix
+ * @return a kernel matrix represented as an array
+ */
+ private static float[] generateDiskKernelArray(float diskRadius,
+ int kernelRadius) {
+ int kernelDim = 2 * kernelRadius + 1;
+ int kernelLength = kernelDim * kernelDim;
+
+ float[] kernel = new float[kernelLength];
+ Arrays.fill(kernel, 0);
+
+ // Generates {@code NUM_SUB_PIXELS*NUM_SUB_PIXELS} sub-pixel shifts {@code
+ // (dx,dy)} uniformly within [-0.5,0.5]*[-0.5,0.5].
+ // For each shift, tests whether or not the shifted pixel is within the
+ // disc and accumulates the count.
+ float diskRadius2 = diskRadius * diskRadius;
+ float dy0 = -0.5f + 1.0f / (2 * getNumSubPixels());
+ float dx0 = -0.5f + 1.0f / (2 * getNumSubPixels());
+
+ float sumKernelValues = 0;
+ for (int v = 0; v < getNumSubPixels(); ++v) {
+ float dy = dy0 + (float) v / (float) getNumSubPixels();
+ for (int u = 0; u < getNumSubPixels(); ++u) {
+ float dx = dx0 + (float) u / (float) getNumSubPixels();
+ for (int y = 0; y < kernelDim; ++y) {
+ float yf = y - kernelRadius + dy;
+ for (int x = 0; x < kernelDim; ++x) {
+ float xf = x - kernelRadius + dx;
+ if (yf * yf + xf * xf <= diskRadius2) {
+ kernel[y * kernelDim + x] += 1;
+ sumKernelValues += 1;
+ }
+ }
+ }
+ }
+ }
+
+ // Normalizes kernel elements such that they sum up to 1.
+ for (int n = 0; n < kernelLength; ++n) {
+ kernel[n] /= sumKernelValues;
+ }
+
+ return kernel;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/RefocusFilterF32.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/RefocusFilterF32.java
new file mode 100644
index 0000000..35b0bd4
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/f32/RefocusFilterF32.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.f32;
+
+
+import android.graphics.Bitmap;
+
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.util.Log;
+
+import android.renderscript.cts.refocus.BlurStack;
+import android.renderscript.cts.refocus.KernelDataForRenderScript;
+import android.renderscript.cts.refocus.LayerInfo;
+import android.renderscript.cts.refocus.MediaStoreSaver;
+import android.renderscript.cts.refocus.RefocusFilter;
+import android.renderscript.cts.refocus.ScriptC_layered_filter_fast_f32;
+
+/**
+ * An accelerated implementation of RefocusFilter using float32 as pixel
+ * representation. The corresponding RenderScript class is
+ * ScriptC_layered_filter_f32. Integral image is used for the speedup.
+ *
+ * Example Usage:
+ *
+ * {@code RenderScript renderScript = RenderScript.create(context);}
+ * {@code RefocusFilterF32 rfFilter = new RefocusFilterF32(renderScript);}
+ * {@code ProgressCallback progress;}
+ * {@code Bitmap result = rfFilter.compute(rgbdImage, blurStack, progress);}
+ *
+ */
+public class RefocusFilterF32 extends
+ RefocusFilter<ScriptC_layered_filter_fast_f32> {
+ private static final String myTAG = "RefocusFilterF32";
+ private static final boolean ENABLE_FAST_FILTER = true;
+ private static final float MIN_DISC_RADIUS_FOR_FAST_FILTER = 3;
+ boolean useFastFilterForCurrentLayer = false;
+ ImageBuffersForRenderScriptF32 buffers;
+
+ public RefocusFilterF32(RenderScript rs) {
+ super(rs);
+ }
+
+ @Override
+ protected void initializeScriptAndBuffers(Bitmap inputImage,
+ LayerInfo focalLayer) {
+ scriptC = new ScriptC_layered_filter_fast_f32(renderScript);
+
+ // Allocates, binds, and initializes buffers that interface between Java
+ // and Render Script.
+ // + 1 is for the boundary case of using integral image.
+ KernelDataForRenderScript.setUseNewRS(false);
+ int margin = KernelDataForRenderScript.getMaxKernelRadius() + 1;
+ buffers = new ImageBuffersForRenderScriptF32(inputImage, margin,
+ renderScript, scriptC);
+ buffers.initializeRenderScript(focalLayer, scriptC);
+ }
+
+ @Override
+ protected Bitmap extractResultImage() {
+ // Extracts the result from .rs file to {@code buffers.outputImage} in Java.
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_PackOutputImage(buffers.outAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "PackOutputImage: "+(endnow - startnow)+ " ns" );
+
+ buffers.outAllocation.copyTo(buffers.outputImage);
+ return buffers.outputImage;
+ }
+
+ /*
+ * Utility Method to extract intermediatory result
+ */
+ private void extractSharpImage(String name) {
+
+ Bitmap mBitmap = Bitmap.createBitmap(buffers.inputImage.getWidth(),
+ buffers.inputImage.getHeight(), Bitmap.Config.ARGB_8888);
+ Allocation mAllocation = Allocation.createFromBitmap(renderScript, mBitmap);
+ scriptC.forEach_PackSharpImage(mAllocation);
+
+ mAllocation.copyTo(mBitmap);
+ MediaStoreSaver.savePNG(mBitmap, "sharpF32", name, renderScript.getApplicationContext());
+ }
+ /*
+ * Utility Method to extract intermediatory result
+ */
+ private void extractFuzzyImage(String name) {
+
+ Bitmap mBitmap = Bitmap.createBitmap(buffers.inputImage.getWidth(),
+ buffers.inputImage.getHeight(), Bitmap.Config.ARGB_8888);
+ Allocation mAllocation = Allocation.createFromBitmap(renderScript, mBitmap);
+ scriptC.forEach_PackFuzzyImage(mAllocation);
+
+ mAllocation.copyTo(mBitmap);
+ MediaStoreSaver.savePNG(mBitmap, "fuzzyF32", name, renderScript.getApplicationContext());
+ }
+
+ @Override
+ protected void setTargetLayer(LayerInfo layerInfo) {
+ scriptC.invoke_SetTargetLayer(layerInfo.frontDepth, layerInfo.backDepth);
+ }
+
+ @Override
+ protected void setBlendInfo(int dilationRadius) {
+ scriptC.invoke_SetBlendInfo(dilationRadius);
+ }
+
+ @Override
+ protected void setKernelData(int targetLayer, BlurStack blurStack) {
+ KernelDataForRenderScriptF32 kernelData =
+ new KernelDataForRenderScriptF32(targetLayer, blurStack, renderScript);
+
+ if (ENABLE_FAST_FILTER
+ && kernelData.minDiskRadius > MIN_DISC_RADIUS_FOR_FAST_FILTER) {
+ useFastFilterForCurrentLayer = true;
+ } else {
+ useFastFilterForCurrentLayer = false;
+ }
+
+ scriptC.bind_g_kernel_info(kernelData.getKernelInfo());
+ scriptC.bind_g_kernel_stack(kernelData.stackAllocation);
+ }
+
+ @Override
+ protected void computeLayerMatteBehindFocalDepth() {
+ // Marks active pixels (pixels that are on this target layer);
+ // Marks adjacent pixels that are close enough to active pixels;
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_MarkLayerMask(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "MarkLayerMask: "+(endnow - startnow)+ " ns" );
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeLayerMatteBehindFocalDepth(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeLayerMatteBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+ }
+
+ @Override
+ protected void filterLayerBehindFocalDepth() {
+ // Filters the target layer and saves the result to {@code g_accum_map} in
+ // .rs file.
+ long startnow;
+ long endnow;
+ if (useFastFilterForCurrentLayer) {
+ scriptC.invoke_SetUseIntegralImage(1);
+ Script.LaunchOptions launchOptions = new Script.LaunchOptions();
+ launchOptions.setX(0, 1);
+ launchOptions.setY(0, buffers.inputImage.getHeight());
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeIntegralImageForLayerBehindFocalDepth(
+ buffers.inAllocation, launchOptions);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeIntegralImageForLayerBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+ } else {
+ scriptC.invoke_SetUseIntegralImage(0);
+ }
+
+ startnow = System.nanoTime();
+ scriptC.forEach_FilterLayerBehindFocalDepth(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "FilterLayerBehindFocalDepth: "+(endnow - startnow)+ " ns" );
+
+ //extractFuzzyImage("fuzzy_behind");
+ //extractSharpImage("sharp_behind");
+ }
+
+ @Override
+ protected void updateSharpImageUsingFuzzyImage() {
+ // Log the kernel execution time
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_UpdateSharpImageUsingFuzzyImage(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "UpdateSharpImageUsingFuzzyImage: "+(endnow - startnow)+ " ns" );
+
+ //extractSharpImage("sharp_update");
+ }
+
+ @Override
+ protected void computeLayerMatteInFrontOfFocalDepth() {
+ // Marks active pixels (pixels that are on this target layer);
+ // Marks adjacent pixels that are close enough to active pixels;
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_MarkLayerMask(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "MarkLayerMask: "+(endnow - startnow)+ " ns" );
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeLayerMatteInFrontOfFocalDepth(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeLayerMatteInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+ }
+
+ @Override
+ protected void filterLayerInFrontOfFocalDepth() {
+ // Filters the target layer and accumulates the result to {@code
+ // g_accum_map} in .rs file.
+ long startnow;
+ long endnow;
+ if (useFastFilterForCurrentLayer) {
+ scriptC.invoke_SetUseIntegralImage(1);
+ Script.LaunchOptions launchOptions = new Script.LaunchOptions();
+ launchOptions.setX(0, 1);
+ launchOptions.setY(0, buffers.inputImage.getHeight());
+
+ startnow = System.nanoTime();
+ scriptC.forEach_ComputeIntegralImageForLayerInFrontOfFocalDepth(
+ buffers.inAllocation, launchOptions);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "ComputeIntegralImageForLayerInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+ } else {
+ scriptC.invoke_SetUseIntegralImage(0);
+ }
+ startnow = System.nanoTime();
+ scriptC.forEach_FilterLayerInFrontOfFocalDepth(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "FilterLayerInFrontOfFocalDepth: "+(endnow - startnow)+ " ns" );
+
+ //extractFuzzyImage("fuzzy_front");
+ //extractSharpImage("sharp_front");
+ }
+
+ @Override
+ protected void finalizeFuzzyImageUsingSharpImage() {
+ // Blends {@code g_accum_map} and {@code g_focus_map} in .rs file.
+ // Saves the result in {@code g_accum_map}.
+ long startnow;
+ long endnow;
+ startnow = System.nanoTime();
+ scriptC.forEach_FinalizeFuzzyImageUsingSharpImage(buffers.inAllocation);
+ endnow = System.nanoTime();
+ Log.d(myTAG, "FinalizeFuzzyImageUsingSharpImage: "+(endnow - startnow)+ " ns" );
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeInverseDepthTransform.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeInverseDepthTransform.java
new file mode 100644
index 0000000..7e414eb
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeInverseDepthTransform.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.image;
+
+import android.renderscript.cts.refocus.DepthTransform;
+
+/**
+ * An implementation of {@code DepthTransform} that uses an inverse
+ * 8-bit representation of depth similar to the OpenGL z-buffer storage.
+ */
+public class RangeInverseDepthTransform implements DepthTransform {
+ public static final String FORMAT = "RangeInverse";
+
+ private final float near;
+ private final float far;
+
+ public RangeInverseDepthTransform(float near, float far) {
+ this.near = near;
+ this.far = far;
+ }
+
+ @Override
+ public float getNear() {
+ return near;
+ }
+
+ @Override
+ public float getFar() {
+ return far;
+ }
+
+ @Override
+ public String getFormat() {
+ return FORMAT;
+ }
+
+ @Override
+ public int quantize(float value) {
+ return Math.max(0, Math.min(255,
+ (int) ((far - near * far / value) / (far - near) * 255f)));
+ }
+
+ @Override
+ public float reconstruct(int value) {
+ return (far * near) / (far - (far - near) *
+ Math.max(0, Math.min(255, value)) / 255f);
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeLinearDepthTransform.java b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeLinearDepthTransform.java
new file mode 100644
index 0000000..796266a
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image/RangeLinearDepthTransform.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2015 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 android.renderscript.cts.refocus.image;
+
+
+import android.renderscript.cts.refocus.DepthTransform;
+
+/**
+ * An implementation of {@code DepthTransform} that uses a linear 8-bit
+ * quantization.
+ */
+public class RangeLinearDepthTransform implements DepthTransform {
+ public static final String FORMAT = "RangeLinear";
+
+ private final float near;
+ private final float far;
+
+ public RangeLinearDepthTransform(float near, float far) {
+ this.near = near;
+ this.far = far;
+ }
+
+ @Override
+ public float getNear() {
+ return near;
+ }
+
+ @Override
+ public float getFar() {
+ return far;
+ }
+
+ @Override
+ public String getFormat() {
+ return FORMAT;
+ }
+
+ @Override
+ public int quantize(float value) {
+ return Math.max(0, Math.min(255,
+ (int) ((value - near) / (far - near) * 255f)));
+ }
+
+ @Override
+ public float reconstruct(int value) {
+ return near + (far - near) * Math.max(0, Math.min(255, value)) / 255f;
+ }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/image_and_kernel.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image_and_kernel.rsh
new file mode 100644
index 0000000..2570647
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/image_and_kernel.rsh
@@ -0,0 +1,32 @@
+#ifndef IMAGE_AND_KERNEL_RSH
+#define IMAGE_AND_KERNEL_RSH
+
+// Image size
+typedef struct ImageSize {
+ // width-by-height is the dimension of a padded image with a margin.
+ int width;
+ int height;
+ // The dimension of the original unpadded image is
+ // (width-2*margin)-by-(height-2*margin).
+ int margin;
+} ImageSize_t;
+
+static void SetImageSize(int w, int h, int m, ImageSize_t *image_size) {
+ image_size->width = w;
+ image_size->height = h;
+ image_size->margin = m;
+}
+
+// Auxiliary information that is needed to extract a kernel matrix from a buffer
+// of a stack of kernel matrices.
+typedef struct KernelInfo {
+ // The starting position of a kernel matrix in a buffer of a stack of kernel
+ // matrices.
+ int offset;
+
+ // The matrix is of size (2*radius_y+1)-by-(2*radius_x+1).
+ int radius_x;
+ int radius_y;
+} KernelInfo_t;
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info.rsh
new file mode 100644
index 0000000..be351d1
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info.rsh
@@ -0,0 +1,46 @@
+#ifndef LAYER_INFO_RSH
+#define LAYER_INFO_RSH
+
+// An object that contains the front and back depths values of a layer
+typedef struct LayerInfo {
+ // Front and back depth values of this layer.
+ // front_depth >= back_depth.
+ int front_depth;
+ int back_depth;
+} LayerInfo_t;
+
+// An object that contains parameters used for computing matte for the current
+// layer.
+typedef struct BlendInfo {
+ // The max kernel radius of a layer.
+ int dilation_radius;
+
+ // A scale factor =1.0f/(1+dilation_radius), which is used to normalize a
+ // distance transform result to be a matte value within [0,1].
+ // This data member is only used for PixelFormatF32.
+ float matte_normalizer;
+} BlendInfo_t;
+
+static inline int ValidDepth(int depth) { return (depth != 0); }
+
+static inline int NotInFrontOfTheLayer(int depth,
+ const LayerInfo_t *layer_info) {
+ return (depth <= layer_info->front_depth);
+}
+
+static inline int OnTheLayer(int depth, const LayerInfo_t *layer_info) {
+ return (layer_info->back_depth <= depth && depth <= layer_info->front_depth);
+}
+
+static inline int ValidDepthNotInFrontOfTheLayer(
+ int depth, const LayerInfo_t *layer_info) {
+ return (depth != 0) & (depth <= layer_info->front_depth);
+}
+
+static inline int ValidDepthNotOnTheLayer(int depth,
+ const LayerInfo_t *layer_info) {
+ return (depth != 0) &
+ ((depth < layer_info->back_depth) | (depth > layer_info->front_depth));
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info_fast.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info_fast.rsh
new file mode 100644
index 0000000..6b7368c
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layer_info_fast.rsh
@@ -0,0 +1,48 @@
+#ifndef LAYER_INFO_RSH
+#define LAYER_INFO_RSH
+
+// An object that contains the front and back depths values of a layer
+typedef struct LayerInfo {
+ // Front and back depth values of this layer.
+ // front_depth >= back_depth.
+ int front_depth;
+ int back_depth;
+} LayerInfo_t;
+
+// An object that contains parameters used for computing matte for the current
+// layer.
+typedef struct BlendInfo {
+ // The max kernel radius of a layer.
+ int dilation_radius;
+
+ // A scale factor =1.0f/(1+dilation_radius), which is used to normalize a
+ // distance transform result to be a matte value within [0,1].
+ // This data member is only used for PixelFormatF32.
+ float matte_normalizer;
+} BlendInfo_t;
+
+static inline int ValidDepth(int depth) { return (depth != 0); }
+
+static inline int NotInFrontOfTheLayer(int depth,
+ const int2 layer_info_f2) {
+ return (depth <= layer_info_f2.s0);
+}
+
+static inline int OnTheLayer(int depth, const int2 layer_info_i2) {
+ //return (layer_info->back_depth <= depth && depth <= layer_info->front_depth);
+ return (layer_info_i2.s1 <= depth && depth <= layer_info_i2.s0);
+}
+
+static inline int ValidDepthNotInFrontOfTheLayer(
+ int depth, const int2 layer_info_f2) {
+ //return (depth != 0) & (depth <= layer_info->front_depth);
+ return (depth != 0) & (depth <= layer_info_f2.s0);
+}
+
+static inline int ValidDepthNotOnTheLayer(int depth,
+ const int2 layer_info_f2) {
+ return (depth != 0) &
+ ((depth < layer_info_f2.s1) | (depth > layer_info_f2.s0));
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_d1new_helper.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_d1new_helper.rsh
new file mode 100644
index 0000000..39c8d90
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_d1new_helper.rsh
@@ -0,0 +1,261 @@
+#ifndef LAYERED_FILTER_FAST_HELPER_RSH
+#define LAYERED_FILTER_FAST_HELPER_RSH
+
+// Need to access global allocation here
+// Declared in layered_filter_fast_f32.rs
+// This allocation has three float values of red, green, blue
+rs_allocation g_sharp_RGBA;
+
+rs_allocation g_sharp_actual_depth;
+rs_allocation g_sharp_active;
+rs_allocation g_sharp_matte;
+rs_allocation g_sharp_dilated_depth;
+
+// This allocation contains four floats: red, green, blue, alpha
+rs_allocation g_fuzzy_RGBA;
+// This allocation contains four floats: red, green, blue, alpha
+rs_allocation g_integral_RGBA;
+// This allocation contains the kernel stack info: only one float per cell
+rs_allocation g_kernel_stack;
+// int2 that stores the target layer info: 1. front_depth, 2. back_depth; declared in layered_filter_f32_helper.rsh
+static int2 g_target_layer_i2;
+
+
+// Several supporting functions that are called by kernel functions defined in
+// layered_filter_f32.rs for refocus rendering.
+// For the following supporting functions, the input arguments have the
+// following meaning:
+//
+// @param x x-coordinate of a pixel in a padded image.
+// @param y y-coordinate of a pixel in a padded image.
+
+// A function that visits neighboring pixels around (x,y) and finds the closest
+// active pixel to (x,y). Sets the closest distance to sharp->matte and sets the
+// depth of the closest pixel to sharp->dilated_depth.
+// When this function is called, the initial value of sharp->dilated_depth is
+// sharp->actual_depth and must be non-zero. However, sharp->actual_depth may or
+// may not be in the depth range of the target layer.
+
+
+//Compute layer matte using global allocation
+static inline void Alloc_ComputeLayerMatteHelper(uchar sharp_input_actual_depth, int index_sharp_meta,
+ const int4 image_size_i4,
+ const int dilation_radius) {
+ const int kernel_center_x = dilation_radius;
+ const int kernel_center_y = dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // Initializes the minimum distance from this pixel to the active pixels on
+ // this layer.
+ int min_dist = dilation_radius + 1;
+ min_dist *= min_dist; // Prepares for L2 distance.
+ int depth = sharp_input_actual_depth; // Get meta data actual_depth
+
+ int current_meta_index = index_sharp_meta - kernel_center_y * image_size_i4.s0 - kernel_center_x; // image_size.width
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size_i4.s0 - kernel_dim_x; // image_size.width
+
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ const uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, current_meta_index);
+ const uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_meta_index);
+ // L_2 distance:
+ int this_dist = i * i + j * j;
+ // Whether or not this is an active pixel with a smaller distance.
+ int cond = (sharp_active && this_dist < min_dist);
+ // Updates min_dist and corresponding depth.
+ min_dist = cond ? this_dist : min_dist;
+ depth = cond ? sharp_actual_depth : depth;
+
+ current_meta_index += jump_to_next_pixel;
+ }
+ current_meta_index += jump_to_next_row;
+ }
+
+ // Converts min_dist to a matte value.
+ rsSetElementAt_uchar(g_sharp_matte, (uchar)(dilation_radius + 1 - (int)half_sqrt((float)min_dist)), index_sharp_meta);
+ // If sharp->matte > 0, depth must be within the depth range of this layer.
+ rsSetElementAt_uchar(g_sharp_dilated_depth, (uchar)depth, index_sharp_meta);
+}
+
+// return sharp_dilated_depth
+static inline uchar ComputeLayerMattePassInputHelper(uchar sharp_input_actual_depth, int index_sharp_meta,
+ const int4 image_size_i4,
+ const int dilation_radius) {
+ const int kernel_center_x = dilation_radius;
+ const int kernel_center_y = dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // Initializes the minimum distance from this pixel to the active pixels on
+ // this layer.
+ int min_dist = dilation_radius + 1;
+ min_dist *= min_dist; // Prepares for L2 distance.
+ int depth = sharp_input_actual_depth; // Get meta data actual_depth
+
+ int current_meta_index = index_sharp_meta - kernel_center_y * image_size_i4.s0 - kernel_center_x; // image_size.width
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size_i4.s0 - kernel_dim_x; // image_size.width
+
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ const uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, current_meta_index);
+ const uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_meta_index);
+ // L_2 distance:
+ int this_dist = i * i + j * j;
+ // Whether or not this is an active pixel with a smaller distance.
+ int cond = (sharp_active && this_dist < min_dist);
+ // Updates min_dist and corresponding depth.
+ min_dist = cond ? this_dist : min_dist;
+ depth = cond ? sharp_actual_depth : depth;
+
+ current_meta_index += jump_to_next_pixel;
+ }
+ current_meta_index += jump_to_next_row;
+ }
+ // Converts min_dist to a matte value.
+ rsSetElementAt_uchar(g_sharp_matte, (uchar)(dilation_radius + 1 - (int)half_sqrt((float)min_dist)), index_sharp_meta);
+ // If sharp->matte > 0, depth must be within the depth range of this layer.
+ return (uchar)depth;
+}
+
+// Filters target layer when processing layers in pass one from the back-most to
+// the sharp depth.
+// Use global allocation for filter from back most layer to focus layer
+static inline float4 AllocFilterLayerBehindFocalDepthHelper(
+ uint32_t x, uint32_t y, const int4 image_size_i4,
+ const int2 layer_info_i2, const float4 alloc_kernel_info,
+ const VisibilityProbability_t *visibility_probability) {
+ float4 result = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_center_x = alloc_kernel_info.s1;
+ const int kernel_center_y = alloc_kernel_info.s2;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+ int current_kernel_index = alloc_kernel_info.s0; // kernel_info.offset
+
+ // Gets the visibility probability lookup table for the target layer depth.
+ const float *vis_prob = visibility_probability->lut[layer_info_i2.s0]; // layer_info.front_depth
+
+ // Locates the top left corner of the window surrounding this pixel.
+ int current_meta_index = (y - kernel_center_y) * image_size_i4.s0 + // image_size.width
+ (x - kernel_center_x);
+
+ // Filters over the window.
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size_i4.s0 - kernel_dim_x; // image_size.width
+
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // Filters only using pixels on or behind this layer to avoid color
+ // bleeding from layers in front of this layer. Doing visibility test in a
+ // soft way using a probability set in a heuristic way.
+ const uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_meta_index);
+ const float4 sharp_RGBA_nbr = rsGetElementAt_float4(g_sharp_RGBA, current_meta_index);
+ const float kernel = rsGetElementAt_float(g_kernel_stack, current_kernel_index);
+
+ const float v_p = vis_prob[sharp_actual_depth];
+
+ const float weight = v_p * (kernel);
+ result.r += weight * sharp_RGBA_nbr.r;
+ result.g += weight * sharp_RGBA_nbr.g;
+ result.b += weight * sharp_RGBA_nbr.b;
+ result.a += weight;
+ current_kernel_index++;
+ current_meta_index += jump_to_next_pixel;
+ }
+ current_meta_index += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result.
+ float factor = 1.0f / result.a;
+ result.r *= factor;
+ result.g *= factor;
+ result.b *= factor;
+ result.a = 1.0f;
+ return result;
+}
+
+// Filter target layer use global allocation using integral image
+static inline float4 AllocFilterLayerUsingRowwiseIntegralImage(
+ uint32_t x, uint32_t y, const int4 image_size_i4,
+ const float4 alloc_kernel_info, const SecantOffset_t *secant_offset) {
+ //const SecantOffset_t *secant_offset) {
+ float4 result = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_radius_y = alloc_kernel_info.s2; // kernel_info->radius_y
+ const int *radius_lut =
+ secant_offset->lut[kernel_radius_y] + g_kMaxKernelRadius;
+
+ // Locates the top left corner index of the window surrounding this pixel.
+ int current_index_integral = (y - kernel_radius_y) * image_size_i4.s0 + x; // image_size.width
+
+ // Filters over the window.
+ const int jump_to_next_row = image_size_i4.s0; // image_size.width
+ for (int j = -kernel_radius_y; j <= kernel_radius_y; ++j) {
+ const int kernel_radius_x_at_y = radius_lut[j];
+ result += rsGetElementAt_float4(g_integral_RGBA, current_index_integral + kernel_radius_x_at_y) -
+ rsGetElementAt_float4(g_integral_RGBA, current_index_integral - kernel_radius_x_at_y - 1);
+ current_index_integral += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result.
+ float factor = 1.0f / result.a;
+ result.r = result.r * factor;
+ result.g = result.g * factor;
+ result.b = result.b * factor;
+ result.a = 1.0f;
+ return result;
+}
+
+// Use global allocation to filter layer from the
+// front most layer to focus layer.
+static inline float4 AllocFilterLayerInFrontOfFocalDepthHelper(
+ uint32_t x, uint32_t y, const int4 image_size_i4,
+ const float4 alloc_kernel_info) {
+ float4 result = {0.f, 0.f, 0.f, 0.f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_center_x = alloc_kernel_info.s1; // kernel_info->radius_x
+ const int kernel_center_y = alloc_kernel_info.s2; // kernel_info->radius_y
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ int current_kernel_index = alloc_kernel_info.s0; // kernel_info->offset
+
+ // Locates the top left corner of the window surrounding this pixel.
+ const int index =
+ (y - kernel_center_y) * image_size_i4.s0 + (x - kernel_center_x); // image_size.width
+ int current_index = index;
+ // Filters over the window.
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size_i4.s0 - kernel_dim_x; // image_size.width
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // Filters only using pixels with valid depth values (i.e. excluding
+ // padded pixels).
+ const float4 sharp_RGBA_nbr = rsGetElementAt_float4(g_sharp_RGBA, current_index);
+ const uchar sharp_meta_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_index);
+ const float kernel = rsGetElementAt_float(g_kernel_stack, current_kernel_index);
+
+ const float flag = ValidDepth(sharp_meta_actual_depth);
+ const float weight = flag * (kernel);
+ result.r += weight * sharp_RGBA_nbr.r;
+ result.g += weight * sharp_RGBA_nbr.g;
+ result.b += weight * sharp_RGBA_nbr.b;
+ result.a += weight;
+ current_kernel_index++;
+ current_index += jump_to_next_pixel;
+ }
+ current_index += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result
+ float fac = 1.0f / result.a;
+ result.r *= fac;
+ result.g *= fac;
+ result.b *= fac;
+ result.a = 1.0f;
+ return result;
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_f32_helper.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_f32_helper.rsh
new file mode 100644
index 0000000..821e7af
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_f32_helper.rsh
@@ -0,0 +1,228 @@
+#ifndef LAYERED_FILTER_F32_HELPER_RSH
+#define LAYERED_FILTER_F32_HELPER_RSH
+
+#include "pixel_format_f32.rsh"
+#include "luts_for_speedup_f32.rsh"
+
+// Several supporting functions that are called by kernel functions defined in
+// layered_filter_f32.rs for refocus rendering.
+// For the following supporting functions, the input arguments have the
+// following meaning:
+//
+// @param x x-coordinate of a pixel in a padded image.
+// @param y y-coordinate of a pixel in a padded image.
+
+// A function that visits neighboring pixels around (x,y) and finds the closest
+// active pixel to (x,y). Sets the closest distance to sharp->matte and sets the
+// depth of the closest pixel to sharp->dilated_depth.
+// When this function is called, the initial value of sharp->dilated_depth is
+// sharp->actual_depth and must be non-zero. However, sharp->actual_depth may or
+// may not be in the depth range of the target layer.
+static inline void ComputeLayerMatteHelper(SharpPixelF32_t *sharp, uint32_t x,
+ uint32_t y,
+ const ImageSize_t *image_size,
+ const int dilation_radius) {
+ const int kernel_center_x = dilation_radius;
+ const int kernel_center_y = dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // Initializes the minimum distance from this pixel to the active pixels on
+ // this layer.
+ int min_dist = dilation_radius + 1;
+ min_dist *= min_dist; // Prepares for L2 distance.
+ int depth = sharp->actual_depth;
+
+ const SharpPixelF32_t *sharp_nbr =
+ sharp - kernel_center_y * image_size->width - kernel_center_x;
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size->width - kernel_dim_x;
+
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // L_2 distance:
+ int this_dist = i * i + j * j;
+ // Whether or not this is an active pixel with a smaller distance.
+ int cond = (sharp_nbr->active && this_dist < min_dist);
+ // Updates min_dist and corresponding depth.
+ min_dist = cond ? this_dist : min_dist;
+ depth = cond ? sharp_nbr->actual_depth : depth;
+
+ sharp_nbr += jump_to_next_pixel;
+ }
+ sharp_nbr += jump_to_next_row;
+ }
+
+ // Converts min_dist to a matte value.
+ sharp->matte = (uchar)(dilation_radius + 1 - (int)half_sqrt((float)min_dist));
+ // If sharp->matte > 0, depth must be within the depth range of this layer.
+ sharp->dilated_depth = (uchar)depth;
+}
+
+// Filters target layer when processing layers in pass one from the back-most to
+// the sharp depth.
+static inline FuzzyPixelF32_t FilterLayerBehindFocalDepthHelper(
+ uint32_t x, uint32_t y, const ImageSize_t *image_size,
+ const LayerInfo_t *layer_info, const KernelInfo_t *kernel_info,
+ const float *kernel_stack, const SharpPixelF32_t *sharp_image,
+ const VisibilityProbability_t *visibility_probability) {
+ FuzzyPixelF32_t result = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_center_x = kernel_info->radius_x;
+ const int kernel_center_y = kernel_info->radius_y;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+ const float *kernel = kernel_stack + kernel_info->offset;
+
+ // Gets the visibility probability lookup table for the target layer depth.
+ const float *vis_prob = visibility_probability->lut[layer_info->front_depth];
+
+ // Locates the top left corner of the window surrounding this pixel.
+ const SharpPixelF32_t *sharp_nbr = sharp_image +
+ (y - kernel_center_y) * image_size->width +
+ (x - kernel_center_x);
+
+ // Filters over the window.
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size->width - kernel_dim_x;
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // Filters only using pixels on or behind this layer to avoid color
+ // bleeding from layers in front of this layer. Doing visibility test in a
+ // soft way using a probability set in a heuristic way.
+ const float v_p = vis_prob[sharp_nbr->actual_depth];
+
+ const float weight = v_p * (*kernel);
+ result.red += weight * sharp_nbr->red;
+ result.green += weight * sharp_nbr->green;
+ result.blue += weight * sharp_nbr->blue;
+ result.alpha += weight;
+ kernel++;
+ sharp_nbr += jump_to_next_pixel;
+ }
+ sharp_nbr += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result.
+ float factor = 1.0f / result.alpha;
+ result.red *= factor;
+ result.green *= factor;
+ result.blue *= factor;
+ result.alpha = 1.0f;
+ return result;
+}
+
+// Filters target layer when processing layers in pass one from the back-most to
+// the sharp depth.
+static inline FuzzyPixelF32_t FilterLayerUsingRowwiseIntegralImage(
+ uint32_t x, uint32_t y, const ImageSize_t *image_size,
+ const KernelInfo_t *kernel_info, const float4 *integral_image,
+ const SecantOffset_t *secant_offset) {
+ float4 result = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_radius_y = kernel_info->radius_y;
+ const int *radius_lut =
+ secant_offset->lut[kernel_radius_y] + g_kMaxKernelRadius;
+
+ // Locates the top left corner of the window surrounding this pixel.
+ const float4 *integral_pixel =
+ integral_image + (y - kernel_radius_y) * image_size->width + x;
+
+ // Filters over the window.
+ const int jump_to_next_row = image_size->width;
+ for (int j = -kernel_radius_y; j <= kernel_radius_y; ++j) {
+ const int kernel_radius_x_at_y = radius_lut[j];
+ result += integral_pixel[kernel_radius_x_at_y] -
+ integral_pixel[-kernel_radius_x_at_y - 1];
+ integral_pixel += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result.
+ FuzzyPixelF32_t fuzzy;
+ float factor = 1.0f / result.a;
+ fuzzy.red = result.r * factor;
+ fuzzy.green = result.g * factor;
+ fuzzy.blue = result.b * factor;
+ fuzzy.alpha = 1.0f;
+ return fuzzy;
+}
+
+// Filters the target layer when processing layers in pass two from the
+// front-most to the focus depth.
+static inline FuzzyPixelF32_t FilterLayerInFrontOfFocalDepthHelper(
+ uint32_t x, uint32_t y, const ImageSize_t *image_size,
+ const KernelInfo_t *kernel_info, const float *kernel_stack,
+ const SharpPixelF32_t *sharp_image) {
+ FuzzyPixelF32_t result = {0.f, 0.f, 0.f, 0.f};
+
+ // Extracts kernel matrix from kernel stack using kernel_info.
+ const int kernel_center_x = kernel_info->radius_x;
+ const int kernel_center_y = kernel_info->radius_y;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+ const float *kernel = kernel_stack + kernel_info->offset;
+
+ // Locates the top left corner of the window surrounding this pixel.
+ const int index =
+ (y - kernel_center_y) * image_size->width + (x - kernel_center_x);
+ const SharpPixelF32_t *sharp_nbr = sharp_image + index;
+
+ // Filters over the window.
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = image_size->width - kernel_dim_x;
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // Filters only using pixels with valid depth values (i.e. excluding
+ // padded pixels).
+ const float flag = ValidDepth(sharp_nbr->actual_depth);
+
+ const float weight = flag * (*kernel);
+ result.red += weight * sharp_nbr->red;
+ result.green += weight * sharp_nbr->green;
+ result.blue += weight * sharp_nbr->blue;
+ result.alpha += weight;
+ kernel++;
+ sharp_nbr += jump_to_next_pixel;
+ }
+ sharp_nbr += jump_to_next_row;
+ }
+
+ // Normalizes and returns the result
+ float fac = 1.0f / result.alpha;
+ result.red *= fac;
+ result.green *= fac;
+ result.blue *= fac;
+ result.alpha = 1.0f;
+ return result;
+}
+
+static void ResetSharpImage(SharpPixelF32_t *sharp_image, int num_pixels) {
+ const SharpPixelF32_t *last_p = sharp_image + num_pixels;
+ for (SharpPixelF32_t *p = sharp_image; p != last_p; ++p) {
+ p->red = 0;
+ p->green = 0;
+ p->blue = 0;
+ p->active = 0;
+ p->dilated_depth = 0;
+ p->actual_depth = 0;
+ p->matte = 0;
+ }
+}
+
+static void ResetIntegralImage(float4 *integral_image, int num_pixels) {
+ const float4 *last_p = integral_image + num_pixels;
+ for (float4 *p = integral_image; p != last_p; ++p) {
+ *p = 0;
+ }
+}
+
+static void ResetFuzzyImage(FuzzyPixelF32_t *fuzzy_image, int num_pixels) {
+ const FuzzyPixelF32_t *last_p = fuzzy_image + num_pixels;
+ for (FuzzyPixelF32_t *p = fuzzy_image; p != last_p; ++p) {
+ p->red = 0;
+ p->green = 0;
+ p->blue = 0;
+ p->alpha = 0;
+ }
+}
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_d1new.rs b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_d1new.rs
new file mode 100644
index 0000000..e7342c6
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_d1new.rs
@@ -0,0 +1,825 @@
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts.refocus)
+#pragma rs_fp_relaxed
+// This is a speedup version of layered_filter_f32.rs using summation table.
+// Several kernel functions and global functions for refocus rendering using
+// Render Script. These functions are accessible from Java side. The assumptions
+// made in this file are (consistent with Java side):
+//
+// 1. The depth value varies between 1 and number of depth levels. 0 is reserved
+// for invalid pixels, e.g., padded pixels around image boundary.
+// 2. The depth value represents inverse depth. Larger depths are closer to the
+// camera.
+// 3. The depth values are grouped into several blending layers.
+// 4. The focal layer (i.e., the global variable g_focal_layer) is the depth
+// value interval that has no blur.
+//
+// For the following kernel functions defined in this rs file, the input
+// arguments have the following meaning:
+//
+// @param in an input RGBD pixel with @in.a being quantized inverse depth.
+// @param x x-coordinate of @param in in the unpadded input image.
+// @param y y-coordinate of @param in in the unpadded input image.
+
+#include "camera_response.rsh"
+#include "layer_info_fast.rsh"
+#include "luts_for_speedup_f32.rsh"
+#include "layered_filter_d1new_helper.rsh"
+
+// Set force CPU variable for kernels:
+// UnpackInputImage, ComputeLayerMatteBehindFocalDepth, ComputeIntegralImageForLayerBehindFocalDepth,
+// FilterLayerBehindFocalDepth, updateSharpImageUsingFuzzyImage, ComputeLayerMatteInFrontOfFocalDepth,
+// FilterLayerInFrontOfFocalDepth
+double cpuDummy = 2.0;
+void foo(double a) {
+
+}
+// Image size of padded images: g_sharp_image and g_fuzzy_image.
+// Float4 that stores the image size info: 1. width, 2. height, 3. margin
+static int4 g_image_size_i4;
+
+static CameraResponse_t g_camera_response;
+
+// This image buffer is used to store input image initially.
+// Then the input image gets updated as each layer is processed from the
+// back-most to the focal depth. This image buffer is padded.
+
+// This image buffer is used to save an integral image of g_sharp_image
+// modulated by the visibility mask.
+
+// whether or not to use integral image in this iteration.
+static int g_use_integral_image;
+
+// This image buffer is used to store output image, both for intermediate
+// results and final result.
+// In the first pass from back-most to focal depth, g_fuzzy_image holds the
+// layer filtering result temporarily and then the result is used to update the
+// input image after each layer is processed.
+// In the second pass from front-most to focal depth, g_fuzzy_image accumulates
+// all the layer filtering results and in the end, the accumulation result is
+// blended with the input image (which has been updated in the first pass) to
+// generate the final result. This image buffer is padded.
+
+// The dilation radius that controls how the current layer should be blended
+// with previous layers.
+static BlendInfo_t g_blend_info;
+
+// The depth level that is in focus.
+// int2 that stores the focal layer info: 1. front_depth, 2. back_depth
+static int2 g_focal_layer_i2;
+
+// This is an allocation to store kernel info: 1. offset, 2. radius_x, 3. radius_y
+rs_allocation galloc_kernel_info;
+
+// Precomputed LUTs for speedup.
+static VisibilityProbability_t g_visibility_probability;
+static SecantOffset_t g_secant_offset;
+
+static const float g_kOneOver255 = 1.0f / 255.0f;
+static const float g_kAlmostOne = .998f;
+
+// (1 << g_kDepthScaleShift) must be the same as BlurStack::DEPTH_SCALE.
+static const int g_kDepthScaleShift = 2;
+// g_kMaxDepth must be the same as BlurStack::MAX_DETPH.
+static const int g_kMaxDepth = 256 >> g_kDepthScaleShift;
+
+// Copies an input (unpadded) RGBD image into g_sharp_image, which has been
+// padded with margin. Initialize other fields.
+void __attribute__((kernel))
+UnpackInputImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ float4 sharp_RGBA;
+ float3 tmp = convert_float3(in.xyz) * g_kOneOver255;
+ sharp_RGBA.r =
+ ApplyLUT_Float(tmp.r, g_camera_response.lut_remove_crf_float);
+ sharp_RGBA.g =
+ ApplyLUT_Float(tmp.g, g_camera_response.lut_remove_crf_float);
+ sharp_RGBA.b =
+ ApplyLUT_Float(tmp.b , g_camera_response.lut_remove_crf_float);
+
+ rsSetElementAt_float4(g_sharp_RGBA, sharp_RGBA, index);
+
+ rsSetElementAt_uchar(g_sharp_actual_depth, g_kMaxDepth - (in.a >> g_kDepthScaleShift), index);
+}
+
+// Marks active pixels that are on the target layer.
+// Initializes the matte of active pixels to be the dilation_radius+1, which is
+// equivalent to 1.
+// Initializes dilated_depth of active pixels and pixels that are close to
+// active pixels to be actual depths.
+void __attribute__((kernel)) MarkLayerMask(uchar4 in, uint32_t x, uint32_t y) {
+ const int actual_depth = g_kMaxDepth - (in.a >> g_kDepthScaleShift);
+ if (!OnTheLayer(actual_depth, g_target_layer_i2)) return;
+
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ // Marks this pixel as active.
+ rsSetElementAt_uchar(g_sharp_active, 1, index);
+ rsSetElementAt_uchar(g_sharp_matte, g_blend_info.dilation_radius + 1, index);
+
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, sharp_actual_depth, index);
+
+ // Next, tries to figure out whether or not this pixel is on the boundary
+ // between active and inactive pixels
+ int is_this_pixel_on_boundary = 0;
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index - g_image_size_i4.s0);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index + g_image_size_i4.s0);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index - 1);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index + 1);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ if (!is_this_pixel_on_boundary) {
+ return;
+ }
+
+ // Marks pixels near the boundary of active pixels to compute matte later.
+ const int kernel_center_x = g_blend_info.dilation_radius;
+ const int kernel_center_y = g_blend_info.dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // index of the current meta data, initailly set to top left sharp meta data
+ // Moves sharp_nbr to the top left corner of this pixel.
+ int current_meta_index = x - (kernel_center_y * g_image_size_i4.s0 + kernel_center_x); // width
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = g_image_size_i4.s0 - kernel_dim_x; // width
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ // Initializes dilated_depth as actual_depth.
+ // The dilated_depth will then be updated in distance transform later.
+ // A valid, non-zero dilated_depth indicates distance transform is
+ // needed for the pixel. Otherwise, the distance transform will be
+ // skipped.
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_meta_index);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, sharp_actual_depth, current_meta_index);
+ current_meta_index += jump_to_next_pixel;
+ }
+ current_meta_index += jump_to_next_row;
+ }
+}
+
+// Another version of MarkLayerMask kernel that directly passes input allocation to kernels
+// Input: g_sharp_actual_depth
+// Output: g_sharp_dilated_depth
+uchar __attribute__((kernel)) MarkLayerMaskPassInput(uchar in_sharp_actual_depth, uint32_t x) {
+ if (!OnTheLayer(in_sharp_actual_depth, g_target_layer_i2)) return rsGetElementAt_uchar(g_sharp_dilated_depth, x);
+
+ // Marks this pixel as active.
+ rsSetElementAt_uchar(g_sharp_active, 1, x);
+ rsSetElementAt_uchar(g_sharp_matte, g_blend_info.dilation_radius + 1, x);
+
+ // Next, tries to figure out whether or not this pixel is on the boundary
+ // between active and inactive pixels
+ int is_this_pixel_on_boundary = 0;
+
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x - g_image_size_i4.s0);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x + g_image_size_i4.s0);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x - 1);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x + 1);
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_actual_depth, g_target_layer_i2);
+
+ if (!is_this_pixel_on_boundary) {
+ return in_sharp_actual_depth;
+ }
+
+ // Marks pixels near the boundary of active pixels to compute matte later.
+ const int kernel_center_x = g_blend_info.dilation_radius;
+ const int kernel_center_y = g_blend_info.dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // index of the current meta data, initailly set to top left sharp meta data
+ // Moves sharp_nbr to the top left corner of this pixel.
+ int current_meta_index = x - (kernel_center_y * g_image_size_i4.s0 + kernel_center_x); // width
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = g_image_size_i4.s0 - kernel_dim_x; // width
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ // Initializes dilated_depth as actual_depth.
+ // The dilated_depth will then be updated in distance transform later.
+ // A valid, non-zero dilated_depth indicates distance transform is
+ // needed for the pixel. Otherwise, the distance transform will be
+ // skipped.
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_meta_index);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, sharp_actual_depth, current_meta_index);
+ current_meta_index += jump_to_next_pixel;
+ }
+ current_meta_index += jump_to_next_row;
+ }
+
+ return in_sharp_actual_depth;
+}
+// Distance transform in processing layers in pass one from the back-most to
+// the sharp depth.
+void __attribute__((kernel))
+ComputeLayerMatteBehindFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, index);
+ uchar sharp_dilated_depth = rsGetElementAt_uchar(g_sharp_dilated_depth, index);
+ if (sharp_active == 0 && sharp_dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index);
+ if (NotInFrontOfTheLayer(sharp_actual_depth, g_target_layer_i2)) {
+ // We do not need to compute matte for depths in front of this layer,
+ // because these pixels will be over-written later and hence we don't need
+ // to blend them now.
+ Alloc_ComputeLayerMatteHelper(sharp_actual_depth, index, g_image_size_i4,
+ g_blend_info.dilation_radius);
+ }
+ }
+}
+// Pass input allocation directly to kernel ComputeLayerMatteBehindFocalDepth
+// Input: g_sharp_dilated_depth
+// Output: g_sharp_dilated_depth
+uchar __attribute__((kernel))
+ComputeLayerMatteBehindFocalDepthPassInput(uchar in_sharp_dilated_depth, uint32_t x) {
+ uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, x);
+ if (sharp_active == 0 && in_sharp_dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x);
+ if (NotInFrontOfTheLayer(sharp_actual_depth, g_target_layer_i2)) {
+ // We do not need to compute matte for depths in front of this layer,
+ // because these pixels will be over-written later and hence we don't need
+ // to blend them now.
+ return ComputeLayerMattePassInputHelper(sharp_actual_depth, x, g_image_size_i4,
+ g_blend_info.dilation_radius);
+ }
+ }
+ return in_sharp_dilated_depth;
+}
+
+// Distance transform in processing layers in pass two from the front-most to
+// the sharp depth.
+void __attribute__((kernel))
+ComputeLayerMatteInFrontOfFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, index);
+ uchar sharp_dilated_depth = rsGetElementAt_uchar(g_sharp_dilated_depth, index);
+ if (sharp_active == 0 && sharp_dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ if (fuzzy_RGBA.a < g_kAlmostOne) {
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index);
+ Alloc_ComputeLayerMatteHelper(sharp_actual_depth, index, g_image_size_i4,
+ g_blend_info.dilation_radius);
+ }
+ }
+}
+
+// Pass input allocation directly into kernel ComputeLayerMatteInFrontOfFocalDepth
+// Input: g_sharp_dilated_depth
+// Output: g_sharp_dilated_depth
+uchar __attribute__((kernel))
+ComputeLayerMatteInFrontOfFocalDepthPassInput(uchar in_sharp_dilated_depth, uint32_t x) {
+ uchar sharp_active = rsGetElementAt_uchar(g_sharp_active, x);
+ if (sharp_active == 0 && in_sharp_dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, x);
+ if (fuzzy_RGBA.a < g_kAlmostOne) {
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, x);
+ return ComputeLayerMattePassInputHelper(sharp_actual_depth,x, g_image_size_i4,
+ g_blend_info.dilation_radius);
+ }
+ }
+ return in_sharp_dilated_depth;
+}
+
+// Computes integral image for target layer in processing layers in pass one
+// from the back-most to the sharp depth.
+void __attribute__((kernel))
+ComputeIntegralImageForLayerBehindFocalDepth(uchar4 in, uint32_t x,
+ uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ // Kernel invocation should make sure x = 0.
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0; // width
+ float4 sharp_RGBA;
+ float4 integral_RGBA;
+ uchar sharp_actual_depth;
+
+ int current_index = index;
+ int last_index = index + g_image_size_i4.s0; // width
+
+ // Gets the visibility probability lookup table for the target layer depth.
+ const float *vis_prob =
+ g_visibility_probability.lut[g_target_layer_i2.s0];
+
+ float4 prev_integral_value = 0;
+ for(; current_index != last_index; current_index++) {
+ sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, current_index);
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_index);
+
+ const float weight = vis_prob[sharp_actual_depth];
+
+ float4 this_value = {weight * sharp_RGBA.r, weight * sharp_RGBA.g,
+ weight * sharp_RGBA.b, weight};
+ prev_integral_value = prev_integral_value + this_value;
+
+ // update pointer image
+ integral_RGBA = prev_integral_value;
+ rsSetElementAt_float4(g_integral_RGBA, integral_RGBA, current_index);
+ }
+}
+
+void __attribute__((kernel))
+ComputeIntegralImageForLayerInFrontOfFocalDepth(uchar4 in, uint32_t x,
+ uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ // Kernel invocation should make sure x = 0.
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0; // width
+
+ float4 sharp_RGBA;
+ float4 integral_RGBA;
+ uchar sharp_actual_depth;
+
+ int current_index = index;
+ int last_index = index + g_image_size_i4.s0; // width
+ float4 prev_integral_value = 0;
+ for(; current_index != last_index; current_index++) {
+ sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, current_index);
+ sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, current_index);
+
+ const float weight = ValidDepth(sharp_actual_depth);
+ float4 this_value = {weight * sharp_RGBA.r, weight * sharp_RGBA.g,
+ weight * sharp_RGBA.b, weight};
+ prev_integral_value = prev_integral_value + this_value;
+
+ // Update image
+ integral_RGBA = prev_integral_value;
+ rsSetElementAt_float4(g_integral_RGBA, integral_RGBA, current_index);
+ }
+}
+
+// Filters target layer in processing layers in pass one from the back-most to
+// the sharp depth.
+void __attribute__((kernel))
+FilterLayerBehindFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ uchar matte = rsGetElementAt_uchar(g_sharp_matte, index);
+ if (matte == 0) {
+ return;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence, the kernel_info below is a valid pointer.
+ uchar sharp_dilated_depth = rsGetElementAt_uchar(g_sharp_dilated_depth, index);
+ const float4 alloc_kernel_info = rsGetElementAt_float4(galloc_kernel_info, sharp_dilated_depth - g_target_layer_i2.s1);
+
+ float4 result;
+ // Saves the filtering result in g_fuzzy_image temporarily.
+ if (g_use_integral_image) {
+ result = AllocFilterLayerUsingRowwiseIntegralImage(
+ x, y, g_image_size_i4, alloc_kernel_info, &g_secant_offset);
+ } else {
+ result = AllocFilterLayerBehindFocalDepthHelper(
+ x, y, g_image_size_i4, g_target_layer_i2,
+ alloc_kernel_info, &g_visibility_probability);
+ }
+ rsSetElementAt_float4(g_fuzzy_RGBA, result, index);
+ // Once the kernel invoke is completed, uses the g_fuzzy_image to update
+ // g_sharp_image.
+}
+
+// Directly pass allocation to kernel FilterLayerBehindFocalDepth
+// Input: g_fuzzy_RGBA
+// Output: g_fuzzy_RGBA
+float4 __attribute__((kernel))
+FilterLayerBehindFocalDepthPassInput(float4 in_fuzzy_RGBA, uint32_t x) {
+ uchar sharp_matte = rsGetElementAt_uchar(g_sharp_matte, x);
+ if (sharp_matte == 0) {
+ return in_fuzzy_RGBA;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence, the kernel_info below is a valid pointer.
+ uchar sharp_dilated_depth = rsGetElementAt_uchar(g_sharp_dilated_depth, x);
+ const float4 alloc_kernel_info = rsGetElementAt_float4(galloc_kernel_info, sharp_dilated_depth - g_target_layer_i2.s1);
+
+ float4 result;
+ // Saves the filtering result in g_fuzzy_image temporarily.
+ if (g_use_integral_image) {
+ result = AllocFilterLayerUsingRowwiseIntegralImage(
+ x, 0, g_image_size_i4, alloc_kernel_info, &g_secant_offset);
+ } else {
+ result = AllocFilterLayerBehindFocalDepthHelper(
+ x, 0, g_image_size_i4, g_target_layer_i2,
+ alloc_kernel_info, &g_visibility_probability);
+ }
+ return result;
+ // Once the kernel invoke is completed, uses the g_fuzzy_image to update
+ // g_sharp_image.
+}
+
+// Filters target layer in processing layers in pass two from the front-most
+// to the focus depth.
+void __attribute__((kernel))
+FilterLayerInFrontOfFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+ uchar depth = rsGetElementAt_uchar(g_sharp_dilated_depth, index);
+
+ if (depth == 0) {
+ return;
+ }
+
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+ uchar matte = rsGetElementAt_uchar(g_sharp_matte, index);
+ // Resets fields of this pixel to prepare for the next iteration.
+
+ // Does not reset sharp->actual_depth, which will be used in future
+ // iterations.
+ rsSetElementAt_uchar(g_sharp_active, 0, index);
+ rsSetElementAt_uchar(g_sharp_matte, 0, index);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, 0, index);
+
+ if (matte == 0) {
+ return;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence kernel_info below is a valid pointer.
+ const float4 alloc_kernel_info = rsGetElementAt_float4(galloc_kernel_info, depth - g_target_layer_i2.s1);
+
+ float4 result;
+
+ if (g_use_integral_image) {
+ result = AllocFilterLayerUsingRowwiseIntegralImage(
+ x, y, g_image_size_i4, alloc_kernel_info, &g_secant_offset);
+ } else {
+ result = AllocFilterLayerInFrontOfFocalDepthHelper(
+ x, y, g_image_size_i4, alloc_kernel_info);
+ }
+
+ // Because matte !=0 here, fuzzy->a < g_kAlmostOne must be true.
+ // Otherwise, ComputeLayerMatteHelper won't be called in
+ // ComputeLayerMatteInFrontOfFocalDepth, which results in a zero matte.
+
+ // Accumulates the filtering result to fuzzy.
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ const float capacity = 1.0f - fuzzy_RGBA.a;
+ const float factor = capacity * (float)matte * g_blend_info.matte_normalizer;
+ fuzzy_RGBA.r += factor * result.r;
+ fuzzy_RGBA.g += factor * result.g;
+ fuzzy_RGBA.b += factor * result.b;
+ fuzzy_RGBA.a += factor;
+ rsSetElementAt_float4(g_fuzzy_RGBA, fuzzy_RGBA, index);
+}
+
+// Pass input allocation directly to kernel FilterLayerInFrontOfFocalDepth
+// Input: g_sharp_dilated_depth
+// Output: g_sharp_dilated_depth
+uchar __attribute__((kernel))
+FilterLayerInFrontOfFocalDepthPassInput(uchar in_sharp_dilated_depth, uint32_t x) {
+ if (in_sharp_dilated_depth == 0) {
+ return 0;
+ }
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+ uchar matte = rsGetElementAt_uchar(g_sharp_matte, x);
+ // Resets fields of this pixel to prepare for the next iteration.
+
+ // Does not reset sharp->actual_depth, which will be used in future
+ // iterations.
+ rsSetElementAt_uchar(g_sharp_active, 0, x);
+ rsSetElementAt_uchar(g_sharp_matte, 0, x);
+
+ if (matte == 0) {
+ return 0;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence kernel_info below is a valid pointer.
+ const float4 alloc_kernel_info = rsGetElementAt_float4(galloc_kernel_info, in_sharp_dilated_depth - g_target_layer_i2.s1);
+
+ float4 result;
+
+ if (g_use_integral_image) {
+ result = AllocFilterLayerUsingRowwiseIntegralImage(
+ x, 0, g_image_size_i4, alloc_kernel_info, &g_secant_offset);
+ } else {
+ result = AllocFilterLayerInFrontOfFocalDepthHelper(
+ x, 0, g_image_size_i4, alloc_kernel_info);
+ }
+
+ // Because matte !=0 here, fuzzy->a < g_kAlmostOne must be true.
+ // Otherwise, ComputeLayerMatteHelper won't be called in
+ // ComputeLayerMatteInFrontOfFocalDepth, which results in a zero matte.
+
+ // Accumulates the filtering result to fuzzy.
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, x);
+ const float capacity = 1.0f - fuzzy_RGBA.a;
+ const float factor = capacity * (float)matte * g_blend_info.matte_normalizer;
+ fuzzy_RGBA.r += factor * result.r;
+ fuzzy_RGBA.g += factor * result.g;
+ fuzzy_RGBA.b += factor * result.b;
+ fuzzy_RGBA.a += factor;
+ rsSetElementAt_float4(g_fuzzy_RGBA, fuzzy_RGBA, x);
+ return 0;
+}
+
+// Replaces active pixels in g_sharp_image with the filtering result saved in
+// g_fuzzy_image. Does the replacement in a soft way by blending g_sharp_image
+// and g_fuzzy_image using the matte field.
+void __attribute__((kernel))
+UpdateSharpImageUsingFuzzyImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ uchar depth = rsGetElementAt_uchar(g_sharp_dilated_depth, index);
+
+ if (depth == 0) {
+ return;
+ }
+
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+
+ // Resets fields of this pixel to prepare for future layer processing (pass
+ // two).
+
+ uchar matte = rsGetElementAt_uchar(g_sharp_matte, index);
+ rsSetElementAt_uchar(g_sharp_active, 0, index);
+ rsSetElementAt_uchar(g_sharp_matte, 0, index);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, 0, index);
+ // Does not reset sharp->actual depth, which will be used in future
+ // layer processing.
+
+ if (matte == 0) {
+ return;
+ }
+
+ float factor = (float)matte * g_blend_info.matte_normalizer;
+ // The following blending amounts to:
+ // sharp = (1 - factor) * sharp + factor * fuzzy.
+ float4 sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, index);
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ sharp_RGBA.r += factor * (fuzzy_RGBA.r - sharp_RGBA.r);
+ sharp_RGBA.g += factor * (fuzzy_RGBA.g - sharp_RGBA.g);
+ sharp_RGBA.b += factor * (fuzzy_RGBA.b - sharp_RGBA.b);
+ fuzzy_RGBA.r = 0;
+ fuzzy_RGBA.g = 0;
+ fuzzy_RGBA.b = 0;
+ fuzzy_RGBA.a = 0;
+ rsSetElementAt_float4(g_sharp_RGBA, sharp_RGBA, index);
+ rsSetElementAt_float4(g_fuzzy_RGBA, fuzzy_RGBA, index);
+}
+
+// Passes allocation for g_sharp_meta from java code
+// so that one rsGetElement is eliminated.
+// Still requires set and get for g_fuzzy_RGBA and g_sharp_RGBA
+// Input: g_sharp_dilated_depth
+// Output: g_sharp_dilated_depth
+uchar __attribute__((kernel))
+UpdateSharpUsingFuzzyPassInput(uchar in_sharp_dilated_depth, uint32_t x) {
+ // Variable in is the uchar4 for sharp_meta
+ if (in_sharp_dilated_depth == 0) {
+ return 0;
+ }
+
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+
+ // Resets fields of this pixel to prepare for future layer processing (pass
+ // two).
+
+ // Index of g_sharp_meta should align with g_fuzzy_RGBA and g_sharp_RGBA
+ uchar matte = rsGetElementAt_uchar(g_sharp_matte, x);
+ rsSetElementAt_uchar(g_sharp_active, 0, x);
+ rsSetElementAt_uchar(g_sharp_matte, 0, x);
+ // Does not reset sharp->actual depth, which will be used in future
+ // layer processing.
+
+ if (matte == 0) {
+ return 0;
+ }
+
+ float factor = (float)matte * g_blend_info.matte_normalizer;
+ // The following blending amounts to:
+ // sharp = (1 - factor) * sharp + factor * fuzzy.
+ float4 sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, x);
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, x);
+ sharp_RGBA.r += factor * (fuzzy_RGBA.r - sharp_RGBA.r);
+ sharp_RGBA.g += factor * (fuzzy_RGBA.g - sharp_RGBA.g);
+ sharp_RGBA.b += factor * (fuzzy_RGBA.b - sharp_RGBA.b);
+ fuzzy_RGBA.r = 0;
+ fuzzy_RGBA.g = 0;
+ fuzzy_RGBA.b = 0;
+ fuzzy_RGBA.a = 0;
+ rsSetElementAt_float4(g_sharp_RGBA, sharp_RGBA, x);
+ rsSetElementAt_float4(g_fuzzy_RGBA, fuzzy_RGBA, x);
+ return 0;
+}
+
+// Fills in the pixels on or behind the focal depth in g_fuzzy_image using
+// pixels in g_sharp_image. Does the filling in a soft way by blending using the
+// matte field.
+void __attribute__((kernel))
+FinalizeFuzzyImageUsingSharpImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ float4 sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, index);
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ uchar sharp_actual_depth = rsGetElementAt_uchar(g_sharp_actual_depth, index);
+
+ if (sharp_actual_depth && sharp_actual_depth <= g_focal_layer_i2.s0) { // g_focal_layer.front_depth
+ float capacity = 1.0f - fuzzy_RGBA.a;
+ fuzzy_RGBA.r += sharp_RGBA.r * capacity;
+ fuzzy_RGBA.g += sharp_RGBA.g * capacity;
+ fuzzy_RGBA.b += sharp_RGBA.b * capacity;
+ fuzzy_RGBA.a = 1.0f;
+ rsSetElementAt_float4(g_fuzzy_RGBA, fuzzy_RGBA, index);
+ }
+}
+// Pass allocation directly to kernel FinalizeFuzzyImageUsingSharpImage
+// Input: g_sharp_actual_depth
+// Output: g_fuzzy_RGBA
+float4 __attribute__((kernel))
+FinalizeFuzzyImageUsingSharpImagePassInput(uchar in_sharp_actual_depth, uint32_t x) {
+ float4 sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, x);
+ float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, x);
+
+ if (in_sharp_actual_depth && in_sharp_actual_depth <= g_focal_layer_i2.s0) { // g_focal_layer.front_depth
+ float capacity = 1.0f - fuzzy_RGBA.a;
+ fuzzy_RGBA.r += sharp_RGBA.r * capacity;
+ fuzzy_RGBA.g += sharp_RGBA.g * capacity;
+ fuzzy_RGBA.b += sharp_RGBA.b * capacity;
+ fuzzy_RGBA.a = 1.0f;
+ return fuzzy_RGBA;
+ }
+ return rsGetElementAt_float4(g_fuzzy_RGBA, x);
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackOutputImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ const float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ float4 result;
+
+ result.r = ApplyLUT_Float(fuzzy_RGBA.r, g_camera_response.lut_apply_crf_float);
+ result.g = ApplyLUT_Float(fuzzy_RGBA.g, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(fuzzy_RGBA.b, g_camera_response.lut_apply_crf_float);
+ result.a = fuzzy_RGBA.a;
+
+ return rsPackColorTo8888(result);
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackSharpImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ const float4 sharp_RGBA = rsGetElementAt_float4(g_sharp_RGBA, index);
+ float4 result;
+
+ result.r = ApplyLUT_Float(sharp_RGBA.r, g_camera_response.lut_apply_crf_float);
+ result.g = ApplyLUT_Float(sharp_RGBA.g, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(sharp_RGBA.b, g_camera_response.lut_apply_crf_float);
+
+ return rsPackColorTo8888(result);
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackFuzzyImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size_i4.s2; // margin
+ y += g_image_size_i4.s2; // margin
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size_i4.s0 + x; // width
+
+ const float4 fuzzy_RGBA = rsGetElementAt_float4(g_fuzzy_RGBA, index);
+ float4 result;
+
+ result.r = ApplyLUT_Float(fuzzy_RGBA.r, g_camera_response.lut_apply_crf_float);
+ result.g = ApplyLUT_Float(fuzzy_RGBA.g, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(fuzzy_RGBA.b, g_camera_response.lut_apply_crf_float);
+ result.a = fuzzy_RGBA.a;
+
+ return rsPackColorTo8888(result);
+}
+
+void SetTargetLayer(int front, int back) {
+ g_target_layer_i2.s0 = front;
+ g_target_layer_i2.s1 = back;
+}
+
+void SetBlendInfo(int radius) {
+ g_blend_info.dilation_radius = radius;
+ g_blend_info.matte_normalizer = 1.0f / (radius + 1);
+}
+
+void SetUseIntegralImage(int use_integral_image) {
+ g_use_integral_image = use_integral_image;
+}
+
+void InitializeFast(int width, int height, int margin, int front, int back) {
+ // Initialize image size
+ g_image_size_i4.s0 = width;
+ g_image_size_i4.s1 = height;
+ g_image_size_i4.s2 = margin;
+
+ // Initialize focal layer
+ g_focal_layer_i2.s0 = front;
+ g_focal_layer_i2.s1 = back;
+
+ const int num_pixels = width * height;
+
+ for(int i = 0; i < num_pixels; i++) {
+ float4 zerof4 = {0.0f, 0.0f, 0.0f, 0.0f};
+ rsSetElementAt_float4(g_sharp_RGBA, zerof4, i);
+ rsSetElementAt_float4(g_fuzzy_RGBA, zerof4, i);
+ rsSetElementAt_float4(g_integral_RGBA, zerof4, i);
+
+ rsSetElementAt_uchar(g_sharp_actual_depth, 0, i);
+ rsSetElementAt_uchar(g_sharp_active, 0, i);
+ rsSetElementAt_uchar(g_sharp_matte, 0, i);
+ rsSetElementAt_uchar(g_sharp_dilated_depth, 0, i);
+ }
+
+ InitializeDefaultCameraResponse(&g_camera_response);
+ InitializeRadiusOffset(&g_secant_offset);
+ InitializeVisibilityProbability(&g_visibility_probability, front, back);
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_f32.rs b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_f32.rs
new file mode 100644
index 0000000..ebb9baf
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/layered_filter_fast_f32.rs
@@ -0,0 +1,565 @@
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts.refocus)
+
+// This is a speedup version of layered_filter_f32.rs using summation table.
+// Several kernel functions and global functions for refocus rendering using
+// Render Script. These functions are accessible from Java side. The assumptions
+// made in this file are (consistent with Java side):
+//
+// 1. The depth value varies between 1 and number of depth levels. 0 is reserved
+// for invalid pixels, e.g., padded pixels around image boundary.
+// 2. The depth value represents inverse depth. Larger depths are closer to the
+// camera.
+// 3. The depth values are grouped into several blending layers.
+// 4. The focal layer (i.e., the global variable g_focal_layer) is the depth
+// value interval that has no blur.
+//
+// For the following kernel functions defined in this rs file, the input
+// arguments have the following meaning:
+//
+// @param in an input RGBD pixel with @in.a being quantized inverse depth.
+// @param x x-coordinate of @param in in the unpadded input image.
+// @param y y-coordinate of @param in in the unpadded input image.
+
+#include "image_and_kernel.rsh"
+#include "camera_response.rsh"
+#include "layer_info.rsh"
+#include "pixel_format_f32.rsh"
+#include "luts_for_speedup_f32.rsh"
+#include "layered_filter_f32_helper.rsh"
+
+// Image size of padded images: g_sharp_image and g_fuzzy_image.
+static ImageSize_t g_image_size;
+
+static CameraResponse_t g_camera_response;
+
+float4 *g_sharp_image_buffer = NULL;
+float4 *g_fuzzy_image_buffer = NULL;
+float4 *g_integral_image_buffer = NULL;
+
+// This image buffer is used to store input image initially.
+// Then the input image gets updated as each layer is processed from the
+// back-most to the focal depth. This image buffer is padded.
+static SharpPixelF32_t *g_sharp_image = NULL;
+
+// This image buffer is used to save an integral image of g_sharp_image
+// modulated by the visibility mask.
+static float4 *g_integral_image = NULL;
+
+// whether or not to use integral image in this iteration.
+static int g_use_integral_image;
+
+// This image buffer is used to store output image, both for intermediate
+// results and final result.
+// In the first pass from back-most to focal depth, g_fuzzy_image holds the
+// layer filtering result temporarily and then the result is used to update the
+// input image after each layer is processed.
+// In the second pass from front-most to focal depth, g_fuzzy_image accumulates
+// all the layer filtering results and in the end, the accumulation result is
+// blended with the input image (which has been updated in the first pass) to
+// generate the final result. This image buffer is padded.
+static FuzzyPixelF32_t *g_fuzzy_image = NULL;
+
+// The info of current layer that is being processed.
+static LayerInfo_t g_target_layer;
+// The dilation radius that controls how the current layer should be blended
+// with previous layers.
+static BlendInfo_t g_blend_info;
+
+// The depth level that is in focus.
+static LayerInfo_t g_focal_layer;
+
+// For depth d, let n = d-g_target_layer.back_depth be the relative depth index.
+// g_kernel_stack+g_kernel_info[n].offset is the pointer to the kernel matrix
+// for this depth level.
+// The kernel has a center at
+// (g_kernel_info[n].radius_x, g_kernel_info[n].radius_y).
+// And the kernel has a size of
+// (2*center_x+1, 2*center_y+1) ;
+float *g_kernel_stack;
+KernelInfo_t *g_kernel_info;
+
+// Precomputed LUTs for speedup.
+static VisibilityProbability_t g_visibility_probability;
+static SecantOffset_t g_secant_offset;
+
+static const float g_kOneOver255 = 1.0f / 255.0f;
+static const float g_kAlmostOne = .998f;
+
+// (1 << g_kDepthScaleShift) must be the same as BlurStack::DEPTH_SCALE.
+static const int g_kDepthScaleShift = 2;
+// g_kMaxDepth must be the same as BlurStack::MAX_DETPH.
+static const int g_kMaxDepth = 256 >> g_kDepthScaleShift;
+
+// Copies an input (unpadded) RGBD image into g_sharp_image, which has been
+// padded with margin. Initialize other fields.
+void __attribute__((kernel))
+UnpackInputImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+ sharp->red = in.r * g_kOneOver255;
+ sharp->green = in.g * g_kOneOver255;
+ sharp->blue = in.b * g_kOneOver255;
+
+ sharp->red =
+ ApplyLUT_Float(sharp->red, g_camera_response.lut_remove_crf_float);
+ sharp->green =
+ ApplyLUT_Float(sharp->green, g_camera_response.lut_remove_crf_float);
+ sharp->blue =
+ ApplyLUT_Float(sharp->blue, g_camera_response.lut_remove_crf_float);
+
+ sharp->actual_depth = g_kMaxDepth - (in.a >> g_kDepthScaleShift);
+
+ sharp->active = 0;
+
+ sharp->matte = 0;
+
+ sharp->dilated_depth = 0;
+}
+
+// Marks active pixels that are on the target layer.
+// Initializes the matte of active pixels to be the dilation_radius+1, which is
+// equivalent to 1.
+// Initializes dilated_depth of active pixels and pixels that are close to
+// active pixels to be actual depths.
+void __attribute__((kernel)) MarkLayerMask(uchar4 in, uint32_t x, uint32_t y) {
+ const int actual_depth = g_kMaxDepth - (in.a >> g_kDepthScaleShift);
+ if (!OnTheLayer(actual_depth, &g_target_layer)) return;
+
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x; // index of this pixel
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ // Marks this pixel as active.
+ sharp->active = 1;
+ sharp->matte = g_blend_info.dilation_radius + 1;
+ sharp->dilated_depth = sharp->actual_depth;
+
+ // Next, tries to figure out whether or not this pixel is on the boundary
+ // between active and inactive pixels
+ int is_this_pixel_on_boundary = 0;
+ SharpPixelF32_t *sharp_nbr = NULL;
+
+ // Top
+ sharp_nbr = sharp - g_image_size.width;
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_nbr->actual_depth, &g_target_layer);
+
+ // Bottom
+ sharp_nbr = sharp + g_image_size.width;
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_nbr->actual_depth, &g_target_layer);
+
+ // Left
+ sharp_nbr = sharp - 1;
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_nbr->actual_depth, &g_target_layer);
+
+ // Right
+ sharp_nbr = sharp + 1;
+ is_this_pixel_on_boundary |=
+ ValidDepthNotOnTheLayer(sharp_nbr->actual_depth, &g_target_layer);
+
+ if (!is_this_pixel_on_boundary) {
+ return;
+ }
+
+ // Marks pixels near the boundary of active pixels to compute matte later.
+ const int kernel_center_x = g_blend_info.dilation_radius;
+ const int kernel_center_y = g_blend_info.dilation_radius;
+ const int kernel_dim_x = 2 * kernel_center_x + 1;
+
+ // Moves sharp_nbr to the top left corner of this pixel.
+ sharp_nbr = sharp - (kernel_center_y * g_image_size.width + kernel_center_x);
+
+ // Visits every pixel in the window of radius (center_x,center_y)
+ // surrounding this pixel.
+ const int jump_to_next_pixel = 1;
+ const int jump_to_next_row = g_image_size.width - kernel_dim_x;
+ for (int j = -kernel_center_y; j <= kernel_center_y; ++j) {
+ for (int i = -kernel_center_x; i <= kernel_center_x; ++i) {
+ // Initializes dilated_depth as actual_depth.
+ // The dilated_depth will then be updated in distance transform later.
+ // A valid, non-zero dilated_depth indicates distance transform is
+ // needed for the pixel. Otherwise, the distance transform will be
+ // skipped.
+ sharp_nbr->dilated_depth = sharp_nbr->actual_depth;
+
+ sharp_nbr += jump_to_next_pixel;
+ }
+ sharp_nbr += jump_to_next_row;
+ }
+}
+
+// Distance transform in processing layers in pass one from the back-most to
+// the sharp depth.
+void __attribute__((kernel))
+ComputeLayerMatteBehindFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ if (sharp->active == 0 && sharp->dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ if (NotInFrontOfTheLayer(sharp->actual_depth, &g_target_layer)) {
+ // We do not need to compute matte for depths in front of this layer,
+ // because these pixels will be over-written later and hence we don't need
+ // to blend them now.
+ ComputeLayerMatteHelper(sharp, x, y, &g_image_size,
+ g_blend_info.dilation_radius);
+ }
+ }
+}
+
+// Distance transform in processing layers in pass two from the front-most to
+// the sharp depth.
+void __attribute__((kernel))
+ComputeLayerMatteInFrontOfFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ if (sharp->active == 0 && sharp->dilated_depth) {
+ // This pixel is not active but within the dilation radius of the active
+ // pixels.
+ FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+ if (fuzzy->alpha < g_kAlmostOne) {
+ // This pixel has not been completely covered by layers in front of the
+ // current layer.
+ ComputeLayerMatteHelper(sharp, x, y, &g_image_size,
+ g_blend_info.dilation_radius);
+ }
+ }
+}
+
+// Computes integral image for target layer in processing layers in pass one
+// from the back-most to the sharp depth.
+void __attribute__((kernel))
+ComputeIntegralImageForLayerBehindFocalDepth(uchar4 in, uint32_t x,
+ uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ // Kernel invocation should make sure x = 0.
+ y += g_image_size.margin;
+
+ // Gets the visibility probability lookup table for the target layer depth.
+ const float *vis_prob =
+ g_visibility_probability.lut[g_target_layer.front_depth];
+
+ const int index = y * g_image_size.width;
+ const SharpPixelF32_t *sharp = g_sharp_image + index;
+ const SharpPixelF32_t *last_sharp = sharp + g_image_size.width;
+ float4 *integral = g_integral_image + index;
+ float4 prev_integral_value = 0;
+ for (; sharp != last_sharp; sharp++, integral++) {
+ const float weight = vis_prob[sharp->actual_depth];
+ float4 this_value = {weight * sharp->red, weight * sharp->green,
+ weight * sharp->blue, weight};
+ *integral = prev_integral_value + this_value;
+ prev_integral_value = *integral;
+ }
+}
+
+void __attribute__((kernel))
+ComputeIntegralImageForLayerInFrontOfFocalDepth(uchar4 in, uint32_t x,
+ uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ // Kernel invocation should make sure x = 0.
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width;
+ const SharpPixelF32_t *sharp = g_sharp_image + index;
+ const SharpPixelF32_t *last_sharp = sharp + g_image_size.width;
+ float4 *integral = g_integral_image + index;
+ float4 prev_integral_value = 0;
+ for (; sharp != last_sharp; sharp++, integral++) {
+ const float weight = ValidDepth(sharp->actual_depth);
+ float4 this_value = {weight * sharp->red, weight * sharp->green,
+ weight * sharp->blue, weight};
+ *integral = prev_integral_value + this_value;
+ prev_integral_value = *integral;
+ }
+}
+
+// Filters target layer in processing layers in pass one from the back-most to
+// the sharp depth.
+void __attribute__((kernel))
+FilterLayerBehindFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ if (sharp->matte == 0) {
+ return;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence, the kernel_info below is a valid pointer.
+ const KernelInfo_t *kernel_info =
+ g_kernel_info + sharp->dilated_depth - g_target_layer.back_depth;
+
+ // Saves the filtering result in g_fuzzy_image temporarily.
+ if (g_use_integral_image) {
+ g_fuzzy_image[index] = FilterLayerUsingRowwiseIntegralImage(
+ x, y, &g_image_size, kernel_info, g_integral_image, &g_secant_offset);
+ } else {
+ g_fuzzy_image[index] = FilterLayerBehindFocalDepthHelper(
+ x, y, &g_image_size, &g_target_layer, kernel_info, g_kernel_stack,
+ g_sharp_image, &g_visibility_probability);
+ }
+ // Once the kernel invoke is completed, uses the g_fuzzy_image to update
+ // g_sharp_image.
+}
+
+// Filters target layer in processing layers in pass two from the front-most
+// to the focus depth.
+void __attribute__((kernel))
+FilterLayerInFrontOfFocalDepth(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ const int depth = sharp->dilated_depth;
+ if (depth == 0) {
+ return;
+ }
+
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+ int matte = sharp->matte;
+
+ // Resets fields of this pixel to prepare for the next iteration.
+ sharp->active = 0;
+ sharp->dilated_depth = 0;
+ sharp->matte = 0;
+ // Does not reset sharp->actual_depth, which will be used in future
+ // iterations.
+
+ if (matte == 0) {
+ return;
+ }
+
+ // At this point, sharp->dilated_depth must be within the depth range of
+ // this target layer. Hence kernel_info below is a valid pointer.
+ const KernelInfo_t *kernel_info =
+ g_kernel_info + depth - g_target_layer.back_depth;
+
+ FuzzyPixelF32_t result;
+ if (g_use_integral_image) {
+ result = FilterLayerUsingRowwiseIntegralImage(
+ x, y, &g_image_size, kernel_info, g_integral_image, &g_secant_offset);
+ } else {
+ result = FilterLayerInFrontOfFocalDepthHelper(
+ x, y, &g_image_size, kernel_info, g_kernel_stack, g_sharp_image);
+ }
+
+ FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+ // Because matte !=0 here, fuzzy->a < g_kAlmostOne must be true.
+ // Otherwise, ComputeLayerMatteHelper won't be called in
+ // ComputeLayerMatteInFrontOfFocalDepth, which results in a zero matte.
+
+ // Accumulates the filtering result to fuzzy.
+ const float capacity = 1.0f - fuzzy->alpha;
+ const float factor = capacity * (float)matte * g_blend_info.matte_normalizer;
+ fuzzy->red += factor * result.red;
+ fuzzy->green += factor * result.green;
+ fuzzy->blue += factor * result.blue;
+ fuzzy->alpha += factor;
+}
+
+// Replaces active pixels in g_sharp_image with the filtering result saved in
+// g_fuzzy_image. Does the replacement in a soft way by blending g_sharp_image
+// and g_fuzzy_image using the matte field.
+void __attribute__((kernel))
+UpdateSharpImageUsingFuzzyImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ const int depth = sharp->dilated_depth;
+
+ if (depth == 0) {
+ return;
+ }
+
+ // At this point, this pixel must be either active or close enough to an
+ // active pixel.
+ // For such a pixel, its matte value can still be zero if its distance
+ // transform to the active pixels is larger than dilation_radius.
+ const int matte = sharp->matte;
+
+ // Resets fields of this pixel to prepare for future layer processing (pass
+ // two).
+ sharp->active = 0;
+ sharp->dilated_depth = 0;
+ sharp->matte = 0;
+ // Does not reset sharp->actual depth, which will be used in future
+ // layer processing.
+
+ if (matte == 0) {
+ return;
+ }
+
+ FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+ float factor = (float)matte * g_blend_info.matte_normalizer;
+ // The following blending amounts to:
+ // sharp = (1 - factor) * sharp + factor * fuzzy.
+ sharp->red += factor * (fuzzy->red - sharp->red);
+ sharp->green += factor * (fuzzy->green - sharp->green);
+ sharp->blue += factor * (fuzzy->blue - sharp->blue);
+
+ fuzzy->red = 0;
+ fuzzy->green = 0;
+ fuzzy->blue = 0;
+ fuzzy->alpha = 0;
+}
+
+// Fills in the pixels on or behind the focal depth in g_fuzzy_image using
+// pixels in g_sharp_image. Does the filling in a soft way by blending using the
+// matte field.
+void __attribute__((kernel))
+FinalizeFuzzyImageUsingSharpImage(uchar4 in, uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ const int index = y * g_image_size.width + x;
+ const SharpPixelF32_t *sharp = g_sharp_image + index;
+ FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+
+ // Tests whether this pixel has a valid depth behind the focal depth.
+ if (sharp->actual_depth && sharp->actual_depth <= g_focal_layer.front_depth) {
+ // The alpha channel for sharp is 1.
+ // fuzzy is a result of accumulation and hence is pre-multiplied with alpha.
+ // The following blending amounts to:
+ // fuzzy = fuzzy + (1 - fuzzy->a) * sharp.
+ float capacity = 1.0f - fuzzy->alpha;
+ fuzzy->red += sharp->red * capacity;
+ fuzzy->green += sharp->green * capacity;
+ fuzzy->blue += sharp->blue * capacity;
+ fuzzy->alpha = 1.0f;
+ }
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackOutputImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size.width + x;
+ const FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+
+ // Applies Camera Response using LUT.
+ float4 result;
+ result.r = ApplyLUT_Float(fuzzy->red, g_camera_response.lut_apply_crf_float);
+ result.g =
+ ApplyLUT_Float(fuzzy->green, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(fuzzy->blue, g_camera_response.lut_apply_crf_float);
+ result.a = fuzzy->alpha;
+
+ return rsPackColorTo8888(result);
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackSharpImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size.width + x;
+ const SharpPixelF32_t *sharp = g_sharp_image + index;
+
+ // Applies Camera Response using LUT.
+ float4 result;
+ result.r = ApplyLUT_Float(sharp->red, g_camera_response.lut_apply_crf_float);
+ result.g =
+ ApplyLUT_Float(sharp->green, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(sharp->blue, g_camera_response.lut_apply_crf_float);
+
+ return rsPackColorTo8888(result);
+}
+
+// Copies g_fuzzy_image to output color image, excluding the padded margin.
+// (x, y) is the pixel coordinate in the output image.
+uchar4 __attribute__((kernel)) PackFuzzyImage(uint32_t x, uint32_t y) {
+ // Maps (x,y) to the padded image coordinate system.
+ x += g_image_size.margin;
+ y += g_image_size.margin;
+
+ // Returns the pixel at (x,y) after applying CRF.
+ const int index = y * g_image_size.width + x;
+ const FuzzyPixelF32_t *fuzzy = g_fuzzy_image + index;
+
+ // Applies Camera Response using LUT.
+ float4 result;
+ result.r = ApplyLUT_Float(fuzzy->red, g_camera_response.lut_apply_crf_float);
+ result.g =
+ ApplyLUT_Float(fuzzy->green, g_camera_response.lut_apply_crf_float);
+ result.b = ApplyLUT_Float(fuzzy->blue, g_camera_response.lut_apply_crf_float);
+ result.a = fuzzy->alpha;
+
+ return rsPackColorTo8888(result);
+}
+
+void SetTargetLayer(int front, int back) {
+ g_target_layer.front_depth = front;
+ g_target_layer.back_depth = back;
+}
+
+void SetBlendInfo(int radius) {
+ g_blend_info.dilation_radius = radius;
+ g_blend_info.matte_normalizer = 1.0f / (radius + 1);
+}
+
+void SetUseIntegralImage(int use_integral_image) {
+ g_use_integral_image = use_integral_image;
+}
+
+void InitializeF32(int width, int height, int margin, int front, int back) {
+ SetImageSize(width, height, margin, &g_image_size);
+ g_focal_layer.front_depth = front;
+ g_focal_layer.back_depth = back;
+
+ g_sharp_image = (SharpPixelF32_t *)g_sharp_image_buffer;
+ g_integral_image = g_integral_image_buffer;
+ g_fuzzy_image = (FuzzyPixelF32_t *)g_fuzzy_image_buffer;
+
+ const int num_pixels = width * height;
+ ResetSharpImage(g_sharp_image, num_pixels);
+ ResetIntegralImage(g_integral_image, num_pixels);
+ ResetFuzzyImage(g_fuzzy_image, num_pixels);
+
+ InitializeRadiusOffset(&g_secant_offset);
+ InitializeVisibilityProbability(&g_visibility_probability, front, back);
+ InitializeDefaultCameraResponse(&g_camera_response);
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/luts_for_speedup_f32.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/luts_for_speedup_f32.rsh
new file mode 100644
index 0000000..0052291
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/luts_for_speedup_f32.rsh
@@ -0,0 +1,81 @@
+#ifndef LUTS_FOR_SPEEDUP_F32_RSH
+#define LUTS_FOR_SPEEDUP_F32_RSH
+
+// Defines several LUTs for speed up for uint8 pixel type.
+
+// Depth Range: [1,g_kMaxDepthValue]; 0 is reserved for invalid pixels.
+// g_kMaxDepthValue must be the same as BlurStack::MAX_DEPTH.
+static const int g_kMaxDepthValue = 64;
+
+// A lookup table that heuristically computes the probability that a layer with
+// depth y is visible in the presence of a pixel with depth x.
+// VisibilityProbability.lut[y][x] = 1.0f/(max(x-y,0)+1).
+// The value range of both x and y is [0,g_kMaxDepthValue].
+// The value range of VisibilityProbability.lut[y][x] is [0,1].
+typedef struct VisibilityProbability {
+ float lut[g_kMaxDepthValue + 1][g_kMaxDepthValue + 1];
+} VisibilityProbability_t;
+
+// Assumes a <= b.
+// When a = b, RemoveInterval(x,a,b) always returns x.
+// When a < b,
+// if x <= a, RemoveInterval(x,a,b) = x;
+// if a < x <= b, RemoveInterval(x,a,b) = a;
+// if b < x, RemoveInterval(x,a,b) = a + (x-b).
+static inline int RemoveInterval(int x, int a, int b) {
+ return (x <= a) ? (x) : (a + max(x - b, 0));
+}
+
+static inline void InitializeVisibilityProbability(
+ VisibilityProbability_t* visibility_probability, int front_focal_depth,
+ int back_focal_depth) {
+ // We expect back_focal_depth <= front_focal_depth.
+ for (int y = 0; y <= g_kMaxDepthValue; y++) {
+ for (int x = 0; x <= g_kMaxDepthValue; x++) {
+ if (y == 0 || x == 0) {
+ visibility_probability->lut[y][x] = 0;
+ } else if (y <= back_focal_depth) {
+ const int z = RemoveInterval(x, back_focal_depth, front_focal_depth);
+ visibility_probability->lut[y][x] = 1.0f / (max(z - y, 0) + 1);
+ } else if (y <= front_focal_depth) {
+ // For a depth value within the focal layer, only depth values in front
+ // of the focal layer are considered as its potential occluders. That
+ // is, a depth value x that has a larger value (closer to the camera)
+ // than y but is still within the focal layer is _not_ considered as an
+ // occluder to y.
+ visibility_probability->lut[y][x] =
+ 1.0f / (max(x - front_focal_depth, 0) + 1);
+ } else {
+ // For depths > front_focal_depth, visibility check is not used in
+ // filtering. So always sets it to 1.
+ visibility_probability->lut[y][x] = 1;
+ }
+ }
+ }
+}
+
+// g_kMaxKernelRadius must match the value returned by
+// KernelDataForRenderScript.computeKernelRadiusFromDiskRadius(
+// BlurStack::MaxDiscRadius).
+static const int g_kMaxKernelRadius = 25 + 1;
+
+// A lookup table that pre-computes x coordinate of the intersection between a
+// circle of radius r and a horizontal line of height y.
+// lut[r][y+g_kMaxKernelRadius] = x;
+// The value range of r is [0,g_kMaxKernelRadius].
+// The value range of y is [-g_kMaxKernelRadius,g_kMaxKernelRadius].
+typedef struct SecantOffset {
+ int lut[g_kMaxKernelRadius + 1][2 * g_kMaxKernelRadius + 1];
+} SecantOffset_t;
+
+static inline void InitializeRadiusOffset(SecantOffset_t* secant_offset) {
+ for (int r = 0; r <= g_kMaxKernelRadius; ++r) {
+ for (int y = -g_kMaxKernelRadius; y <= g_kMaxKernelRadius; ++y) {
+ float tmp = max(0, r * r - y * y);
+ secant_offset->lut[r][y + g_kMaxKernelRadius] =
+ (int)round(half_sqrt(tmp));
+ }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/refocus/pixel_format_f32.rsh b/tests/tests/renderscript/src/android/renderscript/cts/refocus/pixel_format_f32.rsh
new file mode 100644
index 0000000..1ed9902
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/refocus/pixel_format_f32.rsh
@@ -0,0 +1,57 @@
+#ifndef PIXEL_FORMAT_F32_RSH
+#define PIXEL_FORMAT_F32_RSH
+
+// FocusPixel is the pixel format in the input image, which serves the
+// following purposes in the refocus filter pipeline.
+//
+// 1. Initially, it stores the input color (red, green, blue) and the depth
+// value (actual_depth). The actual_depth field is never changed once set.
+//
+// 2. When processing each layer, we use its field (active) to mark
+// whether or not a pixel is on the current target layer. For pixels that are
+// active or not active but "close enough" to an active pixel, a matte value is
+// computed for blending color between layers. "Close enough" means L1 distance
+// is no larger than dilation_radius defined in LayerInfo_t in "layer_info.rsh".
+//
+// 3. After each layer is processed from back-most layer to focal depth layer,
+// the color (red, green, blue) of FocusPixel is updated and ready to be used in
+// layer processing for the next iteration.
+//
+// 4. After each layer is processed from front-most layer to focal depth layer,
+// the color (red, green, blue) of FocusPixel is *not* changed.
+//
+// 5. After each layer is processed in either of the two passes, the fields
+// active, matte, and dilated_depth are reset. However, the field actual_depth
+// field remains untouched once set initially.
+typedef struct SharpPixelF32 {
+ float red;
+ float green;
+ float blue;
+
+ uchar actual_depth;
+
+ // active = 1: the pixel is on the target layer;
+ // active = 0: otherwise.
+ uchar active;
+
+ // matte is between 0 and dilation_radius+1, where dilation_radius is defined
+ // in LayerInfo below.
+ // matte/(dilation_radius+1) is the actual value used in layer blending.
+ uchar matte;
+
+ // For active pixels, dilated_depth is the same as actual depth;
+ // For inactive pixels with non-zero matte, dilated_depth is the depth of the
+ // closest active pixels;
+ // For other pixels, 0 (invalid depth).
+ uchar dilated_depth;
+
+} SharpPixelF32_t;
+
+typedef struct FuzzyPixelF32 {
+ float red;
+ float green;
+ float blue;
+ float alpha;
+} FuzzyPixelF32_t;
+
+#endif
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/small_structs.rs b/tests/tests/renderscript/src/android/renderscript/cts/small_structs.rs
new file mode 100644
index 0000000..2f58151
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/small_structs.rs
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts)
+
+#include "shared.rsh"
+
+// The intention of this test is to ensure that small structs are
+// passed / returned correctly by forEach kernels. "small" here means
+// under 64 bytes in size.
+//
+// The structure of this test is as follows:
+// - allocations are initialized in Java
+// - modify_* kernels change the allocation of small structs
+// - verify_* invokables check that the modification changed the data
+// as expected
+//
+// If there was an issue with passing / returning the small structs,
+// then the verify_* invokable should detect that a value is not
+// stored correctly.
+//
+// The first set of tests, char_array_*, test structs that contain
+// char arrays of various sizes. The second set of tests,
+// two_element_struct_*, test structs that contain two different types
+// (so that non-trivial alignment rules apply).
+
+/******************************************************************************/
+/* Common code */
+/******************************************************************************/
+
+static bool failed = false;
+
+void checkError() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+/******************************************************************************/
+/* Char array testing */
+/******************************************************************************/
+
+static int numCharArrayTestsRun;
+
+#define TOTAL_CHAR_ARRAY_TESTS 64
+
+void checkNumberOfCharArrayTestsRun() {
+ rsDebug("number of char array tests run", numCharArrayTestsRun);
+ if (numCharArrayTestsRun != TOTAL_CHAR_ARRAY_TESTS) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+#define CHAR_ARRAY_TEST(SIZE) \
+typedef struct char_array_##SIZE { char bytes[SIZE]; } \
+ char_array_##SIZE; \
+ \
+char_array_##SIZE RS_KERNEL \
+modify_char_array_##SIZE(char_array_##SIZE in) { \
+ for (int i = 0; i < SIZE; ++i) { \
+ in.bytes[i] += i; \
+ } \
+ return in; \
+} \
+ \
+void verify_char_array_##SIZE(rs_allocation alloc) { \
+ for (int i = 0; i < rsAllocationGetDimX(alloc); ++i) { \
+ struct char_array_##SIZE *elem = \
+ (struct char_array_##SIZE *) rsGetElementAt(alloc, i); \
+ for (int j = 0; j < SIZE; ++j) { \
+ _RS_ASSERT(elem->bytes[j] == 2 * j + 1); \
+ } \
+ } \
+ ++numCharArrayTestsRun; \
+}
+
+CHAR_ARRAY_TEST(1)
+CHAR_ARRAY_TEST(2)
+CHAR_ARRAY_TEST(3)
+CHAR_ARRAY_TEST(4)
+CHAR_ARRAY_TEST(5)
+CHAR_ARRAY_TEST(6)
+CHAR_ARRAY_TEST(7)
+CHAR_ARRAY_TEST(8)
+CHAR_ARRAY_TEST(9)
+CHAR_ARRAY_TEST(10)
+CHAR_ARRAY_TEST(11)
+CHAR_ARRAY_TEST(12)
+CHAR_ARRAY_TEST(13)
+CHAR_ARRAY_TEST(14)
+CHAR_ARRAY_TEST(15)
+CHAR_ARRAY_TEST(16)
+CHAR_ARRAY_TEST(17)
+CHAR_ARRAY_TEST(18)
+CHAR_ARRAY_TEST(19)
+CHAR_ARRAY_TEST(20)
+CHAR_ARRAY_TEST(21)
+CHAR_ARRAY_TEST(22)
+CHAR_ARRAY_TEST(23)
+CHAR_ARRAY_TEST(24)
+CHAR_ARRAY_TEST(25)
+CHAR_ARRAY_TEST(26)
+CHAR_ARRAY_TEST(27)
+CHAR_ARRAY_TEST(28)
+CHAR_ARRAY_TEST(29)
+CHAR_ARRAY_TEST(30)
+CHAR_ARRAY_TEST(31)
+CHAR_ARRAY_TEST(32)
+CHAR_ARRAY_TEST(33)
+CHAR_ARRAY_TEST(34)
+CHAR_ARRAY_TEST(35)
+CHAR_ARRAY_TEST(36)
+CHAR_ARRAY_TEST(37)
+CHAR_ARRAY_TEST(38)
+CHAR_ARRAY_TEST(39)
+CHAR_ARRAY_TEST(40)
+CHAR_ARRAY_TEST(41)
+CHAR_ARRAY_TEST(42)
+CHAR_ARRAY_TEST(43)
+CHAR_ARRAY_TEST(44)
+CHAR_ARRAY_TEST(45)
+CHAR_ARRAY_TEST(46)
+CHAR_ARRAY_TEST(47)
+CHAR_ARRAY_TEST(48)
+CHAR_ARRAY_TEST(49)
+CHAR_ARRAY_TEST(50)
+CHAR_ARRAY_TEST(51)
+CHAR_ARRAY_TEST(52)
+CHAR_ARRAY_TEST(53)
+CHAR_ARRAY_TEST(54)
+CHAR_ARRAY_TEST(55)
+CHAR_ARRAY_TEST(56)
+CHAR_ARRAY_TEST(57)
+CHAR_ARRAY_TEST(58)
+CHAR_ARRAY_TEST(59)
+CHAR_ARRAY_TEST(60)
+CHAR_ARRAY_TEST(61)
+CHAR_ARRAY_TEST(62)
+CHAR_ARRAY_TEST(63)
+CHAR_ARRAY_TEST(64)
+
+/******************************************************************************/
+/* Two element struct testing */
+/******************************************************************************/
+
+static int numTwoElementStructTestsRun;
+
+#define TOTAL_TWO_ELEMENT_STRUCT_TESTS 49
+
+void checkNumberOfTwoElementStructTestsRun() {
+ rsDebug("number of two element struct tests run", numTwoElementStructTestsRun);
+ if (numTwoElementStructTestsRun != TOTAL_TWO_ELEMENT_STRUCT_TESTS) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+#define TWO_ELEMENT_STRUCT_TEST(TAG, TYPE1, TYPE2) \
+typedef struct two_element_struct_##TAG { TYPE1 a; TYPE2 b; } \
+ two_element_struct_##TAG; \
+ \
+two_element_struct_##TAG RS_KERNEL \
+modify_two_element_struct_##TAG(two_element_struct_##TAG in, int32_t x) { \
+ in.a += initial_value_##TYPE1 * (x % 3); \
+ in.b += initial_value_##TYPE2 * (x % 4); \
+ return in; \
+} \
+ \
+void verify_two_element_struct_##TAG(rs_allocation alloc) { \
+ for (int i = 0; i < rsAllocationGetDimX(alloc); ++i) { \
+ struct two_element_struct_##TAG *elem = \
+ (struct two_element_struct_##TAG *) rsGetElementAt(alloc, i); \
+ _RS_ASSERT(equals_##TYPE1(elem->a, (1 + (i % 3)) * initial_value_##TYPE1)); \
+ _RS_ASSERT(equals_##TYPE2(elem->b, (1 + (i % 4)) * initial_value_##TYPE2)); \
+ } \
+ ++numTwoElementStructTestsRun; \
+}
+
+int8_t initial_value_int8_t;
+int16_t initial_value_int16_t;
+int32_t initial_value_int32_t;
+int64_t initial_value_int64_t;
+float initial_value_float;
+double initial_value_double;
+float4 initial_value_float4;
+
+#define MAKE_SCALAR_EQUALS(TYPE) \
+static bool equals_##TYPE(TYPE a, TYPE b) { return a == b; }
+
+MAKE_SCALAR_EQUALS(int8_t)
+MAKE_SCALAR_EQUALS(int16_t)
+MAKE_SCALAR_EQUALS(int32_t)
+MAKE_SCALAR_EQUALS(int64_t)
+MAKE_SCALAR_EQUALS(float)
+MAKE_SCALAR_EQUALS(double)
+
+static bool equals_float4(float4 a, float4 b) {
+ return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
+}
+
+#define MAKE_TWO_ELEMENT_STRUCT_TEST(LHS_TAG, LHS_TYPE) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_i8, LHS_TYPE, int8_t) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_i16, LHS_TYPE, int16_t) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_i32, LHS_TYPE, int32_t) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_i64, LHS_TYPE, int64_t) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_f32, LHS_TYPE, float) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_f64, LHS_TYPE, double) \
+TWO_ELEMENT_STRUCT_TEST(LHS_TAG##_v128, LHS_TYPE, float4)
+
+MAKE_TWO_ELEMENT_STRUCT_TEST(i8, int8_t)
+MAKE_TWO_ELEMENT_STRUCT_TEST(i16, int16_t)
+MAKE_TWO_ELEMENT_STRUCT_TEST(i32, int32_t)
+MAKE_TWO_ELEMENT_STRUCT_TEST(i64, int64_t)
+MAKE_TWO_ELEMENT_STRUCT_TEST(f32, float)
+MAKE_TWO_ELEMENT_STRUCT_TEST(f64, double)
+MAKE_TWO_ELEMENT_STRUCT_TEST(v128, float4)
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/verify.rs b/tests/tests/renderscript/src/android/renderscript/cts/verify.rs
index c3ae802..4527f1e 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/verify.rs
+++ b/tests/tests/renderscript/src/android/renderscript/cts/verify.rs
@@ -18,8 +18,6 @@
int gAllowedIntError = 0;
float gAllowedFloatError = 0.0001f;
-double gAllowedFloatMatError = 0.00000001;
-double gAllowedDoubleMatError = 0.00000000001;
static bool hadError = false;
static int2 errorLoc = {0,0};
@@ -303,135 +301,6 @@
}
}
-
-static bool verify_CMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
- uint32_t w = rsAllocationGetDimX(in1);
- uint32_t h = rsAllocationGetDimY(in1);
- for (uint32_t y = 0; y < h; y++) {
- uint32_t xStart = 0;
- if (isUpperMatrix) {
- // Just test the upper matrix for certain BLAS routines
- xStart = y;
- }
- for (uint32_t x = xStart; x < w; x++) {
- float2 pref = rsGetElementAt_float2(in1, x, y);
- float2 ptst = rsGetElementAt_float2(in2, x, y);
- double absErr = (pref.x - ptst.x) * (pref.x - ptst.x) + (pref.y - ptst.y) * (pref.y - ptst.y);
- if (absErr > l2Norm * gAllowedFloatMatError) {
- errorLoc.x = x;
- errorLoc.y = y;
- hadError = true;
- return false;
- }
- }
- }
- return true;
-}
-
-static bool verify_SMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
- uint32_t w = rsAllocationGetDimX(in1);
- uint32_t h = rsAllocationGetDimY(in1);
- for (uint32_t y = 0; y < h; y++) {
- uint32_t xStart = 0;
- if (isUpperMatrix) {
- // Just test the upper matrix for certain BLAS routines
- xStart = y;
- }
- for (uint32_t x = xStart; x < w; x++) {
- float pref = rsGetElementAt_float(in1, x, y);
- float ptst = rsGetElementAt_float(in2, x, y);
- double absErr = (pref - ptst) * (pref - ptst);
- if (absErr > l2Norm * gAllowedFloatMatError) {
- errorLoc.x = x;
- errorLoc.y = y;
- hadError = true;
- return false;
- }
- }
- }
- return true;
-}
-
-static bool verify_ZMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
- uint32_t w = rsAllocationGetDimX(in1);
- uint32_t h = rsAllocationGetDimY(in1);
- for (uint32_t y = 0; y < h; y++) {
- uint32_t xStart = 0;
- if (isUpperMatrix) {
- // Just test the upper matrix for certain BLAS routines
- xStart = y;
- }
- for (uint32_t x = xStart; x < w; x++) {
- double2 pref = rsGetElementAt_double2(in1, x, y);
- double2 ptst = rsGetElementAt_double2(in2, x, y);
- double absErr = (pref.x - ptst.x) * (pref.x - ptst.x) + (pref.y - ptst.y) * (pref.y - ptst.y);
- if (absErr > l2Norm * gAllowedDoubleMatError) {
- errorLoc.x = x;
- errorLoc.y = y;
- hadError = true;
- return false;
- }
- }
- }
- return true;
-}
-
-static bool verify_DMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
- uint32_t w = rsAllocationGetDimX(in1);
- uint32_t h = rsAllocationGetDimY(in1);
- for (uint32_t y = 0; y < h; y++) {
- uint32_t xStart = 0;
- if (isUpperMatrix) {
- // Just test the upper matrix for certain BLAS routines
- xStart = y;
- }
- for (uint32_t x = xStart; x < w; x++) {
- double pref = rsGetElementAt_double(in1, x, y);
- double ptst = rsGetElementAt_double(in2, x, y);
- double absErr = (pref - ptst) * (pref - ptst);
- if (absErr > l2Norm * gAllowedDoubleMatError) {
- errorLoc.x = x;
- errorLoc.y = y;
- hadError = true;
- return false;
- }
- }
- }
- return true;
-}
-
-void verifyMatrix(rs_allocation ref_in, rs_allocation tst_in, double l2Norm, bool isUpperMatrix) {
- rs_element e = rsAllocationGetElement(ref_in);
- rs_data_type dt = rsElementGetDataType(e);
- uint32_t vs = rsElementGetVectorSize(e);
- bool valid = false;
-
- if (dt == RS_TYPE_FLOAT_32) {
- switch(vs) {
- case 2:
- valid = verify_CMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
- break;
- case 1:
- valid = verify_SMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
- break;
- }
- } else if (dt == RS_TYPE_FLOAT_64) {
- switch(vs) {
- case 2:
- valid = verify_ZMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
- break;
- case 1:
- valid = verify_DMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
- break;
- }
- }
- if (!valid) {
- rsDebug("verify failure at xy", errorLoc);
- printCell("Expected value ", ref_in, errorLoc);
- printCell("Actual value ", tst_in, errorLoc);
- }
-}
-
void checkError()
{
if (hadError) {
diff --git a/tests/tests/rsblas/Android.mk b/tests/tests/rsblas/Android.mk
new file mode 100644
index 0000000..b3edfac
--- /dev/null
+++ b/tests/tests/rsblas/Android.mk
@@ -0,0 +1,40 @@
+# Copyright (C) 2015 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := CtsRsBlasTestCases
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# Include both the 32 and 64 bit versions
+LOCAL_MULTILIB := both
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_JNI_SHARED_LIBRARIES := libbnnmdata_jni
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
+
+LOCAL_RENDERSCRIPT_FLAGS := -Wno-error=deprecated-declarations
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_PACKAGE)
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/rsblas/AndroidManifest.xml b/tests/tests/rsblas/AndroidManifest.xml
new file mode 100644
index 0000000..f6099fb
--- /dev/null
+++ b/tests/tests/rsblas/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.rsblas">
+
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!-- This is a self-instrumenting test package. -->
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.cts.rsblas"
+ android:label="CTS tests of RenderScript IntrinsicBLAS">
+ <meta-data android:name="listener"
+ android:value="com.android.cts.runner.CtsTestRunListener" />
+ </instrumentation>
+
+</manifest>
+
diff --git a/tests/tests/renderscript/assets/BLASData.txt b/tests/tests/rsblas/assets/BLASData.txt
similarity index 100%
rename from tests/tests/renderscript/assets/BLASData.txt
rename to tests/tests/rsblas/assets/BLASData.txt
diff --git a/tests/tests/renderscript/assets/blas_gen.py b/tests/tests/rsblas/assets/blas_gen.py
similarity index 100%
rename from tests/tests/renderscript/assets/blas_gen.py
rename to tests/tests/rsblas/assets/blas_gen.py
diff --git a/tests/tests/renderscript/libbnnmdata/Android.mk b/tests/tests/rsblas/libbnnmdata/Android.mk
similarity index 100%
rename from tests/tests/renderscript/libbnnmdata/Android.mk
rename to tests/tests/rsblas/libbnnmdata/Android.mk
diff --git a/tests/tests/renderscript/libbnnmdata/test_data.cpp b/tests/tests/rsblas/libbnnmdata/test_data.cpp
similarity index 99%
rename from tests/tests/renderscript/libbnnmdata/test_data.cpp
rename to tests/tests/rsblas/libbnnmdata/test_data.cpp
index 91222c2..a7dbd1a 100644
--- a/tests/tests/renderscript/libbnnmdata/test_data.cpp
+++ b/tests/tests/rsblas/libbnnmdata/test_data.cpp
@@ -56569,12 +56569,12 @@
extern "C" JNIEXPORT void JNICALL
-Java_android_renderscript_cts_BNNMTest_getData(JNIEnv * env,
- jclass,
- jbyteArray a,
- jbyteArray b,
- jbyteArray c
- )
+Java_android_cts_rsblas_BNNMTest_getData(JNIEnv * env,
+ jclass,
+ jbyteArray a,
+ jbyteArray b,
+ jbyteArray c
+ )
{
jbyte * a_byte = (jbyte *) env->GetPrimitiveArrayCritical(a, 0);
jbyte * b_byte = (jbyte *) env->GetPrimitiveArrayCritical(b, 0);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/BLASData.java b/tests/tests/rsblas/src/android/renderscript/cts/BLASData.java
similarity index 99%
rename from tests/tests/renderscript/src/android/renderscript/cts/BLASData.java
rename to tests/tests/rsblas/src/android/renderscript/cts/BLASData.java
index def0352..786290e 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/BLASData.java
+++ b/tests/tests/rsblas/src/android/renderscript/cts/BLASData.java
@@ -17,7 +17,7 @@
/* Don't edit this file alone!
* The array names need to match the data generated by blas_gen.py. */
-package android.renderscript.cts;
+package android.cts.rsblas;
import android.content.res.AssetManager;
import android.content.Context;
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/BNNMTest.java b/tests/tests/rsblas/src/android/renderscript/cts/BNNMTest.java
similarity index 99%
rename from tests/tests/renderscript/src/android/renderscript/cts/BNNMTest.java
rename to tests/tests/rsblas/src/android/renderscript/cts/BNNMTest.java
index 1822f6a..f95ad3c 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/BNNMTest.java
+++ b/tests/tests/rsblas/src/android/renderscript/cts/BNNMTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.renderscript.cts;
+package android.cts.rsblas;
import android.renderscript.*;
import android.util.Log;
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java b/tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBLAS.java
similarity index 99%
rename from tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java
rename to tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBLAS.java
index 17f546b..a5fc80d 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java
+++ b/tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBLAS.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.renderscript.cts;
+package android.cts.rsblas;
import android.renderscript.*;
import android.util.Log;
diff --git a/tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBase.java b/tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBase.java
new file mode 100644
index 0000000..5ab52b0
--- /dev/null
+++ b/tests/tests/rsblas/src/android/renderscript/cts/IntrinsicBase.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 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 android.cts.rsblas;
+
+import android.util.Log;
+import android.renderscript.RenderScript;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Type;
+import android.renderscript.Script;
+
+public class IntrinsicBase extends RSBaseCompute {
+ protected final String TAG = "Img";
+
+ protected Allocation mAllocSrc;
+ protected Allocation mAllocRef;
+ protected Allocation mAllocDst;
+ protected ScriptC_verify mVerify;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mVerify = new ScriptC_verify(mRS);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (mVerify != null) {
+ mVerify.destroy();
+ mVerify = null;
+ }
+ super.tearDown();
+ }
+
+ protected void checkError() {
+ mRS.finish();
+ mVerify.invoke_checkError();
+ waitForMessage();
+ checkForErrors();
+ }
+}
diff --git a/tests/tests/rsblas/src/android/renderscript/cts/RSBase.java b/tests/tests/rsblas/src/android/renderscript/cts/RSBase.java
new file mode 100644
index 0000000..7057fd9
--- /dev/null
+++ b/tests/tests/rsblas/src/android/renderscript/cts/RSBase.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2015 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 android.cts.rsblas;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.RenderScript.RSErrorHandler;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.renderscript.RSRuntimeException;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+/**
+ * Base RenderScript test class. This class provides a message handler and a
+ * convenient way to wait for compute scripts to complete their execution.
+ */
+public class RSBase extends AndroidTestCase {
+
+ Context mCtx;
+ Resources mRes;
+
+ private int result;
+ // msgHandled is used to synchronize between waitForMessage() and the
+ // RSMessageHandler thread.
+ private volatile boolean msgHandled;
+
+ protected static final int RS_MSG_TEST_PASSED = 100;
+ protected static final int RS_MSG_TEST_FAILED = 101;
+ protected static final int RS_MSG_TEST_FLUSH = 102;
+
+ RSMessageHandler mRsMessage = new RSMessageHandler() {
+ public void run() {
+ if (result == 0) {
+ switch (mID) {
+ case RS_MSG_TEST_PASSED:
+ case RS_MSG_TEST_FAILED:
+ result = mID;
+ break;
+ case RS_MSG_TEST_FLUSH:
+ break;
+ default:
+ fail("Got unexpected RS message");
+ return;
+ }
+ }
+ msgHandled = true;
+ }
+ };
+
+ protected void waitForMessage() {
+ while (!msgHandled) {
+ Thread.yield();
+ }
+ }
+
+ protected boolean FoundError = false;
+ protected RSErrorHandler mRsError = new RSErrorHandler() {
+ public void run() {
+ FoundError = true;
+ Log.e("RenderscriptCTS", mErrorMessage);
+ throw new RSRuntimeException("Received error " + mErrorNum +
+ " message " + mErrorMessage);
+ }
+ };
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ result = 0;
+ msgHandled = false;
+ mCtx = getContext();
+ mRes = mCtx.getResources();
+ }
+
+ /**
+ * Verify that we didn't fail on the control or script side of things.
+ */
+ protected void checkForErrors() {
+ assertFalse(FoundError);
+ assertTrue(result != RS_MSG_TEST_FAILED);
+ }
+}
diff --git a/tests/tests/rsblas/src/android/renderscript/cts/RSBaseCompute.java b/tests/tests/rsblas/src/android/renderscript/cts/RSBaseCompute.java
new file mode 100644
index 0000000..d548a70
--- /dev/null
+++ b/tests/tests/rsblas/src/android/renderscript/cts/RSBaseCompute.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 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 android.cts.rsblas;
+
+import android.renderscript.RenderScript;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RSRuntimeException;
+import android.util.Log;
+
+/**
+ * Base RenderScript test class. This class provides a message handler and a
+ * convenient way to wait for compute scripts to complete their execution.
+ */
+public class RSBaseCompute extends RSBase {
+ RenderScript mRS;
+ protected int INPUTSIZE = 512;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mRS = RenderScript.create(mCtx);
+ mRS.setMessageHandler(mRsMessage);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}
diff --git a/tests/tests/rsblas/src/android/renderscript/cts/shared.rsh b/tests/tests/rsblas/src/android/renderscript/cts/shared.rsh
new file mode 100644
index 0000000..d20fd34
--- /dev/null
+++ b/tests/tests/rsblas/src/android/renderscript/cts/shared.rsh
@@ -0,0 +1,26 @@
+#pragma version(1)
+#pragma rs java_package_name(android.cts.rsblas)
+
+static int64_t g_time;
+
+static inline void start(void) {
+ g_time = rsUptimeMillis();
+}
+
+static inline float end(void) {
+ int64_t t = rsUptimeMillis() - g_time;
+ return ((float)t) / 1000.f;
+}
+
+#define _RS_ASSERT(b) \
+do { \
+ if (!(b)) { \
+ failed = true; \
+ rsDebug(#b " FAILED", 0); \
+ } \
+\
+} while (0)
+
+/* These constants must match those in UnitTest.java */
+static const int RS_MSG_TEST_PASSED = 100;
+static const int RS_MSG_TEST_FAILED = 101;
diff --git a/tests/tests/rsblas/src/android/renderscript/cts/verify.rs b/tests/tests/rsblas/src/android/renderscript/cts/verify.rs
new file mode 100644
index 0000000..ea3cff6
--- /dev/null
+++ b/tests/tests/rsblas/src/android/renderscript/cts/verify.rs
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#include "shared.rsh"
+
+double gAllowedFloatMatError = 0.00000001;
+double gAllowedDoubleMatError = 0.00000000001;
+static bool hadError = false;
+static int2 errorLoc = {0,0};
+
+#define printCell(txt, a, xy) \
+{ \
+ rs_element e = rsAllocationGetElement(a); \
+ rs_data_type dt = rsElementGetDataType(e); \
+ uint32_t vs = rsElementGetVectorSize(e); \
+ \
+ if (dt == RS_TYPE_UNSIGNED_8) { \
+ switch(vs) { \
+ case 4: \
+ rsDebug(txt, rsGetElementAt_uchar4(a, xy.x, xy.y)); \
+ break; \
+ case 3: \
+ rsDebug(txt, rsGetElementAt_uchar3(a, xy.x, xy.y)); \
+ break; \
+ case 2: \
+ rsDebug(txt, rsGetElementAt_uchar2(a, xy.x, xy.y)); \
+ break; \
+ case 1: \
+ rsDebug(txt, rsGetElementAt_uchar(a, xy.x, xy.y)); \
+ break; \
+ } \
+ } else if (dt == RS_TYPE_FLOAT_32) { \
+ switch(vs) { \
+ case 4: \
+ rsDebug(txt, rsGetElementAt_float4(a, xy.x, xy.y)); \
+ break; \
+ case 3: \
+ rsDebug(txt, rsGetElementAt_float3(a, xy.x, xy.y)); \
+ break; \
+ case 2: \
+ rsDebug(txt, rsGetElementAt_float2(a, xy.x, xy.y)); \
+ break; \
+ case 1: \
+ rsDebug(txt, rsGetElementAt_float(a, xy.x, xy.y)); \
+ break; \
+ } \
+ } else if (dt == RS_TYPE_FLOAT_64) { \
+ switch(vs) { \
+ case 4: \
+ rsDebug(txt, rsGetElementAt_double4(a, xy.x, xy.y)); \
+ break; \
+ case 3: \
+ rsDebug(txt, rsGetElementAt_double3(a, xy.x, xy.y)); \
+ break; \
+ case 2: \
+ rsDebug(txt, rsGetElementAt_double2(a, xy.x, xy.y)); \
+ break; \
+ case 1: \
+ rsDebug(txt, rsGetElementAt_double(a, xy.x, xy.y)); \
+ } \
+ } \
+}
+
+static bool verify_CMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
+ uint32_t w = rsAllocationGetDimX(in1);
+ uint32_t h = rsAllocationGetDimY(in1);
+ for (uint32_t y = 0; y < h; y++) {
+ uint32_t xStart = 0;
+ if (isUpperMatrix) {
+ // Just test the upper matrix for certain BLAS routines
+ xStart = y;
+ }
+ for (uint32_t x = xStart; x < w; x++) {
+ float2 pref = rsGetElementAt_float2(in1, x, y);
+ float2 ptst = rsGetElementAt_float2(in2, x, y);
+ double absErr = (pref.x - ptst.x) * (pref.x - ptst.x) + (pref.y - ptst.y) * (pref.y - ptst.y);
+ if (absErr > l2Norm * gAllowedFloatMatError) {
+ errorLoc.x = x;
+ errorLoc.y = y;
+ hadError = true;
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool verify_SMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
+ uint32_t w = rsAllocationGetDimX(in1);
+ uint32_t h = rsAllocationGetDimY(in1);
+ for (uint32_t y = 0; y < h; y++) {
+ uint32_t xStart = 0;
+ if (isUpperMatrix) {
+ // Just test the upper matrix for certain BLAS routines
+ xStart = y;
+ }
+ for (uint32_t x = xStart; x < w; x++) {
+ float pref = rsGetElementAt_float(in1, x, y);
+ float ptst = rsGetElementAt_float(in2, x, y);
+ double absErr = (pref - ptst) * (pref - ptst);
+ if (absErr > l2Norm * gAllowedFloatMatError) {
+ errorLoc.x = x;
+ errorLoc.y = y;
+ hadError = true;
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool verify_ZMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
+ uint32_t w = rsAllocationGetDimX(in1);
+ uint32_t h = rsAllocationGetDimY(in1);
+ for (uint32_t y = 0; y < h; y++) {
+ uint32_t xStart = 0;
+ if (isUpperMatrix) {
+ // Just test the upper matrix for certain BLAS routines
+ xStart = y;
+ }
+ for (uint32_t x = xStart; x < w; x++) {
+ double2 pref = rsGetElementAt_double2(in1, x, y);
+ double2 ptst = rsGetElementAt_double2(in2, x, y);
+ double absErr = (pref.x - ptst.x) * (pref.x - ptst.x) + (pref.y - ptst.y) * (pref.y - ptst.y);
+ if (absErr > l2Norm * gAllowedDoubleMatError) {
+ errorLoc.x = x;
+ errorLoc.y = y;
+ hadError = true;
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool verify_DMatrix(rs_allocation in1, rs_allocation in2, double l2Norm, bool isUpperMatrix) {
+ uint32_t w = rsAllocationGetDimX(in1);
+ uint32_t h = rsAllocationGetDimY(in1);
+ for (uint32_t y = 0; y < h; y++) {
+ uint32_t xStart = 0;
+ if (isUpperMatrix) {
+ // Just test the upper matrix for certain BLAS routines
+ xStart = y;
+ }
+ for (uint32_t x = xStart; x < w; x++) {
+ double pref = rsGetElementAt_double(in1, x, y);
+ double ptst = rsGetElementAt_double(in2, x, y);
+ double absErr = (pref - ptst) * (pref - ptst);
+ if (absErr > l2Norm * gAllowedDoubleMatError) {
+ errorLoc.x = x;
+ errorLoc.y = y;
+ hadError = true;
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+void verifyMatrix(rs_allocation ref_in, rs_allocation tst_in, double l2Norm, bool isUpperMatrix) {
+ rs_element e = rsAllocationGetElement(ref_in);
+ rs_data_type dt = rsElementGetDataType(e);
+ uint32_t vs = rsElementGetVectorSize(e);
+ bool valid = false;
+
+ if (dt == RS_TYPE_FLOAT_32) {
+ switch(vs) {
+ case 2:
+ valid = verify_CMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
+ break;
+ case 1:
+ valid = verify_SMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
+ break;
+ }
+ } else if (dt == RS_TYPE_FLOAT_64) {
+ switch(vs) {
+ case 2:
+ valid = verify_ZMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
+ break;
+ case 1:
+ valid = verify_DMatrix(ref_in, tst_in, l2Norm, isUpperMatrix);
+ break;
+ }
+ }
+ if (!valid) {
+ rsDebug("verify failure at xy", errorLoc);
+ printCell("Expected value ", ref_in, errorLoc);
+ printCell("Actual value ", tst_in, errorLoc);
+ }
+}
+
+void checkError()
+{
+ if (hadError) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/tests/rscpp/librscpptest/Android.mk b/tests/tests/rscpp/librscpptest/Android.mk
index df8ce29f..73d2234 100644
--- a/tests/tests/rscpp/librscpptest/Android.mk
+++ b/tests/tests/rscpp/librscpptest/Android.mk
@@ -45,14 +45,12 @@
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
+LOCAL_CPPFLAGS := -std=c++11
+
LOCAL_SHARED_LIBRARIES := libdl liblog
LOCAL_STATIC_LIBRARIES := libRScpp_static libcutils
-ifeq ($(my_32_64_bit_suffix),32)
- LOCAL_SDK_VERSION := 8
-else
- LOCAL_SDK_VERSION := 21
-endif
+LOCAL_SDK_VERSION := 21
LOCAL_NDK_STL_VARIANT := stlport_static
diff --git a/tests/tests/rscpp/librscpptest/rs_jni.cpp b/tests/tests/rscpp/librscpptest/rs_jni.cpp
index 4e60f4b..920d95d 100644
--- a/tests/tests/rscpp/librscpptest/rs_jni.cpp
+++ b/tests/tests/rscpp/librscpptest/rs_jni.cpp
@@ -459,7 +459,7 @@
sp<RS> mRS = new RS();
mRS->init(path);
- RSYuvFormat mYuvFormat = (RSYuvFormat)yuvFormat;
+ RsYuvFormat mYuvFormat = (RsYuvFormat)yuvFormat;
sp<ScriptIntrinsicYuvToRGB> syuv = ScriptIntrinsicYuvToRGB::create(mRS, Element::U8_4(mRS));;
sp<Allocation> inputAlloc = nullptr;
@@ -492,4 +492,3 @@
return (mRS->getError() == RS_SUCCESS);
}
-
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSYuvTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSYuvTest.java
index 8f79a4c..30c76e4 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSYuvTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSYuvTest.java
@@ -141,7 +141,8 @@
syuv.forEach(aout);
byte[] nativeByteAlloc = new byte[width * height * 4];
- yuvTest(this.getContext().getCacheDir().toString(), width, height, tmp, nativeByteAlloc, 1);
+ yuvTest(this.getContext().getCacheDir().toString(), width, height, tmp, nativeByteAlloc,
+ android.graphics.ImageFormat.YV12);
aref.copyFromUnchecked(nativeByteAlloc);
mVerify.invoke_verify(aref, aout, ay);
@@ -177,7 +178,8 @@
syuv.forEach(aout);
byte[] nativeByteAlloc = new byte[width * height * 4];
- yuvTest(this.getContext().getCacheDir().toString(), width, height, tmp, nativeByteAlloc, 2);
+ yuvTest(this.getContext().getCacheDir().toString(), width, height, tmp, nativeByteAlloc,
+ android.graphics.ImageFormat.NV21);
aref.copyFromUnchecked(nativeByteAlloc);
mVerify.invoke_verify(aref, aout, ay);
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index ec36d6d..08750d6 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -25,7 +25,7 @@
LOCAL_JAVA_LIBRARIES := android.test.runner org.apache.http.legacy
-LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni libcts_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni libcts_jni libnativehelper_compat_libc++
LOCAL_SRC_FILES := $(call all-java-files-under, src)\
src/android/security/cts/activity/ISecureRandomService.aidl
diff --git a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
index f73b2f42..c097359 100644
--- a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
+++ b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
@@ -79,7 +79,7 @@
return JNI_ERR;
}
- if (register_android_security_cts_AudioEffectBinderTest(env)) {
+ if (register_android_security_cts_AudioEffectBinderTest(env)) {
return JNI_ERR;
}
diff --git a/tests/tests/security/src/android/security/cts/BannedFilesTest.java b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
index 00c4631..54709b4 100644
--- a/tests/tests/security/src/android/security/cts/BannedFilesTest.java
+++ b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
@@ -58,6 +58,17 @@
assertFalse("/dev/socket/fotabinder", new File("/dev/socket/fotabinder").exists());
}
+ /**
+ * Detect devices allowing shell commands to be executed as system
+ * through sockets.
+ *
+ * ANDROID-19679287
+ * CVE-2015-2231
+ */
+ public void testNoSystemCmdSocket() {
+ assertFalse("/dev/socket/fota", new File("/dev/socket/fota").exists());
+ }
+
public void testNoSu() {
assertFalse("/sbin/su", new File("/sbin/su").exists());
assertFalse("/system/bin/su", new File("/system/bin/su").exists());
diff --git a/tests/tests/text/src/android/text/cts/TextUtilsTest.java b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
index 694513e..9258318 100644
--- a/tests/tests/text/src/android/text/cts/TextUtilsTest.java
+++ b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
@@ -44,9 +44,6 @@
import android.util.Log;
import android.util.StringBuilderPrinter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.util.ArrayList;
import java.util.Locale;
import java.util.regex.Pattern;
@@ -2033,11 +2030,6 @@
assertTrue(builder.length() > 0);
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getLayoutDirectionFromLocale",
- args = {Locale.class}
- )
public void testGetLayoutDirectionFromLocale() {
assertEquals(LAYOUT_DIRECTION_LTR,
TextUtils.getLayoutDirectionFromLocale(null));
diff --git a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
index 8ca1fea..1808c85 100644
--- a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
@@ -28,6 +28,7 @@
import java.text.SimpleDateFormat;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -257,4 +258,36 @@
checkFormat("12", "h", 24);
checkFormat( "0", "H", 24);
}
+
+ public void test_bug_82144() {
+ for (Locale locale : Locale.getAvailableLocales()) {
+ if (locale.toString().startsWith("haw")) {
+ // http://b/26397197 - remove this when fixed.
+ continue;
+ }
+ Locale.setDefault(locale);
+ char[] order = DateFormat.getDateFormatOrder(mContext);
+ boolean seenDay = false, seenMonth = false, seenYear = false;
+ for (char c : order) {
+ switch (c) {
+ case 'd':
+ seenDay = true;
+ break;
+ case 'M':
+ seenMonth = true;
+ break;
+ case 'y':
+ seenYear = true;
+ break;
+ default:
+ fail("Unknown character: " + c + " in " + Arrays.toString(order)
+ + " for " + locale);
+ break;
+ }
+ }
+ assertTrue(locale.toString() + " day not found", seenDay);
+ assertTrue(locale.toString() + " month not found", seenMonth);
+ assertTrue(locale.toString() + " year not found", seenYear);
+ }
+ }
}
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index 9ab815f..f0a4d09 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -19,7 +19,6 @@
import android.content.Context;
import android.test.AndroidTestCase;
import android.text.format.DateUtils;
-import dalvik.annotation.KnownFailure;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
diff --git a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
index 061cda3..a8d68dc 100644
--- a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
@@ -16,8 +16,6 @@
package android.text.method.cts;
-import dalvik.annotation.KnownFailure;
-
import android.cts.util.WidgetTestUtils;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
diff --git a/tests/tests/util/Android.mk b/tests/tests/util/Android.mk
index 75d23d7..44a67dc 100644
--- a/tests/tests/util/Android.mk
+++ b/tests/tests/util/Android.mk
@@ -27,6 +27,4 @@
LOCAL_PACKAGE_NAME := CtsUtilTestCases
-LOCAL_SDK_VERSION := current
-
include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/util/assets/Integrate.jar b/tests/tests/util/assets/Integrate.jar
new file mode 100644
index 0000000..16e9c55
--- /dev/null
+++ b/tests/tests/util/assets/Integrate.jar
Binary files differ
diff --git a/tests/tests/util/assets/Modified_Class.jar b/tests/tests/util/assets/Modified_Class.jar
new file mode 100644
index 0000000..d8113c7
--- /dev/null
+++ b/tests/tests/util/assets/Modified_Class.jar
Binary files differ
diff --git a/tests/tests/util/assets/Modified_Manifest_EntryAttributes.jar b/tests/tests/util/assets/Modified_Manifest_EntryAttributes.jar
new file mode 100644
index 0000000..bd1dbb1
--- /dev/null
+++ b/tests/tests/util/assets/Modified_Manifest_EntryAttributes.jar
Binary files differ
diff --git a/tests/tests/util/assets/Modified_Manifest_MainAttributes.jar b/tests/tests/util/assets/Modified_Manifest_MainAttributes.jar
new file mode 100644
index 0000000..5bc60e6
--- /dev/null
+++ b/tests/tests/util/assets/Modified_Manifest_MainAttributes.jar
Binary files differ
diff --git a/tests/tests/util/assets/Modified_SF_EntryAttributes.jar b/tests/tests/util/assets/Modified_SF_EntryAttributes.jar
new file mode 100644
index 0000000..7b76694
--- /dev/null
+++ b/tests/tests/util/assets/Modified_SF_EntryAttributes.jar
Binary files differ
diff --git a/tests/tests/util/assets/hyts_patch.jar b/tests/tests/util/assets/hyts_patch.jar
new file mode 100644
index 0000000..f3c51d0
--- /dev/null
+++ b/tests/tests/util/assets/hyts_patch.jar
Binary files differ
diff --git a/tests/tests/util/assets/removed.jar b/tests/tests/util/assets/removed.jar
new file mode 100644
index 0000000..2100322
--- /dev/null
+++ b/tests/tests/util/assets/removed.jar
Binary files differ
diff --git a/tests/tests/util/src/android/util/cts/StrictJarFileTest.java b/tests/tests/util/src/android/util/cts/StrictJarFileTest.java
new file mode 100644
index 0000000..e7eedfd
--- /dev/null
+++ b/tests/tests/util/src/android/util/cts/StrictJarFileTest.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2013 Google Inc.
+ *
+ * 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 android.util.cts;
+
+import android.test.AndroidTestCase;
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Iterator;
+import android.util.jar.StrictJarFile;
+import java.util.zip.ZipEntry;
+import libcore.io.Streams;
+
+public class StrictJarFileTest extends AndroidTestCase {
+
+ // A well formed jar file with 6 entries.
+ private static final String JAR_1 = "hyts_patch.jar";
+
+ private File resources;
+
+ @Override
+ protected void setUp() {
+ try {
+ resources = File.createTempFile("sjf_resources", "", null);
+ resources.delete();
+ resources.mkdirs();
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to create temp folder", e);
+ }
+ resources.deleteOnExit();
+ }
+
+ public void testConstructor() throws Exception {
+ try {
+ StrictJarFile jarFile = new StrictJarFile("Wrong.file");
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+
+ copyFile(JAR_1);
+ String fileName = (new File(resources, JAR_1)).getCanonicalPath();
+ StrictJarFile jarFile = new StrictJarFile(fileName);
+ jarFile.close();
+ }
+
+ public void testIteration() throws Exception {
+ copyFile(JAR_1);
+ StrictJarFile jarFile = new StrictJarFile(new File(resources, JAR_1).getAbsolutePath());
+
+ Iterator<ZipEntry> it = jarFile.iterator();
+ HashMap<String, ZipEntry> entries = new HashMap<String, ZipEntry>();
+ while (it.hasNext()) {
+ final ZipEntry ze = it.next();
+ entries.put(ze.getName(), ze);
+ }
+
+ assertEquals(6, entries.size());
+ assertTrue(entries.containsKey("META-INF/"));
+
+ assertTrue(entries.containsKey("META-INF/MANIFEST.MF"));
+ ZipEntry ze = entries.get("META-INF/MANIFEST.MF");
+ assertEquals(62, ze.getSize());
+ assertEquals(ZipEntry.DEFLATED, ze.getMethod());
+ assertEquals(61, ze.getCompressedSize());
+
+ assertTrue(entries.containsKey("Blah.txt"));
+ ze = entries.get("Blah.txt");
+ assertEquals(4, ze.getSize());
+ assertEquals(ZipEntry.DEFLATED, ze.getMethod());
+ assertEquals(6, ze.getCompressedSize());
+ assertEquals("Blah", new String(Streams.readFully(jarFile.getInputStream(ze)),
+ Charset.forName("UTF-8")));
+
+ assertTrue(entries.containsKey("foo/"));
+ assertTrue(entries.containsKey("foo/bar/"));
+ assertTrue(entries.containsKey("foo/bar/A.class"));
+ ze = entries.get("foo/bar/A.class");
+ assertEquals(311, ze.getSize());
+ assertEquals(ZipEntry.DEFLATED, ze.getMethod());
+ assertEquals(225, ze.getCompressedSize());
+ }
+
+ public void testFindEntry() throws Exception {
+ copyFile(JAR_1);
+ StrictJarFile jarFile = new StrictJarFile(new File(resources, JAR_1).getAbsolutePath());
+
+ assertNull(jarFile.findEntry("foobar"));
+ assertNull(jarFile.findEntry("blah.txt"));
+ assertNotNull(jarFile.findEntry("Blah.txt"));
+ final ZipEntry ze = jarFile.findEntry("Blah.txt");
+ assertEquals(4, ze.getSize());
+ assertEquals(ZipEntry.DEFLATED, ze.getMethod());
+ assertEquals(6, ze.getCompressedSize());
+ assertEquals("Blah", new String(Streams.readFully(jarFile.getInputStream(ze)),
+ Charset.forName("UTF-8")));
+ }
+
+ public void testGetManifest() throws Exception {
+ copyFile(JAR_1);
+ StrictJarFile jarFile = new StrictJarFile(new File(resources, JAR_1).getAbsolutePath());
+
+ assertNotNull(jarFile.getManifest());
+ assertEquals("1.4.2 (IBM Corporation)", jarFile.getManifest().getMainAttributes().getValue("Created-By"));
+ }
+
+ public void testJarSigning_wellFormed() throws IOException {
+ copyFile("Integrate.jar");
+ StrictJarFile jarFile = new StrictJarFile(new File(resources, "Integrate.jar").getAbsolutePath());
+ Iterator<ZipEntry> entries = jarFile.iterator();
+ while (entries.hasNext()) {
+ ZipEntry zipEntry = entries.next();
+ jarFile.getInputStream(zipEntry).skip(Long.MAX_VALUE);
+ if ("Test.class".equals(zipEntry.getName())) {
+ assertNotNull(jarFile.getCertificates(zipEntry));
+ assertNotNull(jarFile.getCertificateChains(zipEntry));
+ }
+ }
+ }
+
+ public void testJarSigning_fudgedEntry() throws IOException {
+ copyFile("Integrate.jar");
+ StrictJarFile jarFile = new StrictJarFile(
+ new File(resources, "Integrate.jar").getAbsolutePath());
+
+ ZipEntry ze = jarFile.findEntry("Test.class");
+ jarFile.getInputStream(ze).skip(Long.MAX_VALUE);
+
+ // Fudge the size so that certificates do not match.
+ ze.setSize(ze.getSize() - 1);
+ try {
+ jarFile.getInputStream(ze).skip(Long.MAX_VALUE);
+ fail();
+ } catch (SecurityException expected) {
+ }
+ }
+
+ public void testJarSigning_modifiedClass() throws IOException {
+ copyFile("Modified_Class.jar");
+ StrictJarFile jarFile = new StrictJarFile(
+ new File(resources, "Modified_Class.jar").getAbsolutePath());
+
+ ZipEntry ze = jarFile.findEntry("Test.class");
+ try {
+ jarFile.getInputStream(ze).skip(Long.MAX_VALUE);
+ fail();
+ } catch (SecurityException expected) {
+ }
+ }
+
+ public void testJarSigning_brokenMainAttributes() throws Exception {
+ assertThrowsOnInit("Modified_Manifest_MainAttributes.jar");
+ }
+
+ public void testJarSigning_brokenEntryAttributes() throws Exception {
+ assertThrowsOnInit("Modified_Manifest_EntryAttributes.jar");
+ }
+
+ public void testJarSigning_brokenSignatureFile() throws Exception {
+ assertThrowsOnInit("Modified_SF_EntryAttributes.jar");
+ }
+
+ public void testJarSigning_removedEntry() throws Exception {
+ assertThrowsOnInit("removed.jar");
+ }
+
+ private void assertThrowsOnInit(String name) throws Exception {
+ copyFile(name);
+ try {
+ StrictJarFile jarFile = new StrictJarFile(
+ new File(resources, name).getAbsolutePath());
+ fail();
+ } catch (SecurityException expected) {
+ }
+ }
+
+
+ public File copyFile(String file) {
+ File dest = new File(resources.toString() + "/" + file);
+
+ if (!dest.exists()) {
+ try {
+ InputStream in = getContext().getAssets().open(file);
+ FileOutputStream out = new FileOutputStream(dest);
+ byte[] buffer = new byte[8192];
+ int c;
+ while ((c = in.read(buffer)) != -1) {
+ out.write(buffer, 0, c);
+ }
+ out.close();
+ dest.deleteOnExit();
+ in.close();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Unable to copy file from resource " + file + " to file " + dest, e);
+ }
+ }
+ return dest;
+ }
+}
diff --git a/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java b/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
index eb75557..95f8d0c 100644
--- a/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
@@ -170,7 +170,7 @@
if (target != null) {
target.close();
}
- } catch (IOException _) {
+ } catch (IOException ignored) {
// Ignore the IOException.
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
index aa1df34..8b50e2c 100644
--- a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
@@ -95,7 +95,7 @@
if (target != null) {
target.close();
}
- } catch (IOException _) {
+ } catch (IOException ignored) {
// Ignore the IOException.
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java b/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
index 49bc767..9f3aa55 100644
--- a/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
@@ -182,7 +182,7 @@
if (target != null) {
target.close();
}
- } catch (final IOException _) {
+ } catch (final IOException ignored) {
// Ignore the IOException.
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
index 58738a1..18bac7e 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
@@ -633,7 +633,7 @@
if (target != null) {
target.close();
}
- } catch (IOException _) {
+ } catch (IOException ignored) {
// Ignore the IOException.
}
}
diff --git a/tools/signature-tools/Android.mk b/tools/signature-tools/Android.mk
deleted file mode 100644
index cf9e053..0000000
--- a/tools/signature-tools/Android.mk
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (C) 2008 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.
-
-LOCAL_PATH := $(call my-dir)
-
-# signature-tools java library
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under,src)
-LOCAL_JAVA_RESOURCE_DIRS := templates
-
-LOCAL_MODULE := signature-tools
-LOCAL_JAVA_LIBRARIES := dx dex-tools
-LOCAL_STATIC_JAVA_LIBRARIES := stringtemplate antlr-2.7.7
-LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-# prebuilt stringtemplate.jar
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_JAVA_LIBRARIES := stringtemplate:lib/stringtemplate.jar
-
-include $(BUILD_HOST_PREBUILT)
-
-# prebuilt antlr-2.7.7.jar
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_JAVA_LIBRARIES := antlr-2.7.7:lib/antlr-2.7.7.jar
-
-include $(BUILD_HOST_PREBUILT)
-
-# signature-tool script
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := sig
-include $(BUILD_HOST_PREBUILT)
-
-# signature-create script
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := sig-create
-include $(BUILD_HOST_PREBUILT)
-
-# signature-check script
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := sig-check
-include $(BUILD_HOST_PREBUILT)
diff --git a/tools/signature-tools/README.txt b/tools/signature-tools/README.txt
deleted file mode 100644
index b4198b9..0000000
--- a/tools/signature-tools/README.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-__signature-tools__
-
-This project contains the source code and tests for API signature comparison tools.
-It consists roughly of five parts:
-
-#Signature model : A generic model to represent the structure of an API
-
-#Converters : A dex -> signature model converter (utilizing the dex-tools parser)
- A java source -> signature model converter (utilizing the doclet tools)
-
-#Delta model : A model to represent differences between two signature models
-
-#Comparator : Put two signature models into the comparator and you get a delta model
-
-#Report engine : Translates a delta model to a html output based on templates (utilizing the StringTemplate framework)
-
-
-Since this folder contains a .project file, it can be imported directly into eclipse as a java project.
-
-Feel free to improve!
-
-_Structure_
-
-dex.reader
- |
- src : source code
- | |
- | signature : the driver classes
- | |
- | compare : the comparator code
- | | |
- | | model : the delta model
- | |
- | converter : the converters
- | |
- | io : common io interfaces
- | | |
- | | html : html report generator
- | |
- | model : signature model
- |
- test : source code of the test suite
- |
- templates : templates for html output generation
- |
- launches : eclipse launches for the tools
- |
- lib : required libraries
- |
- spec : various input files to try the tool
- |
- README.txt : you are here
- |
- TODO.txt : tasks which are still open
-
diff --git a/tools/signature-tools/TODO.txt b/tools/signature-tools/TODO.txt
deleted file mode 100644
index fd20800..0000000
--- a/tools/signature-tools/TODO.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-__Todo__
-
-Add more complex tests
-Add more spec
-Add "plugin system" to enable different loader / differ / report engines. This can be simple as register the class name of the available loaders in a property file
diff --git a/tools/signature-tools/lib/antlr-2.7.7.jar b/tools/signature-tools/lib/antlr-2.7.7.jar
deleted file mode 100644
index 5e5f14b..0000000
--- a/tools/signature-tools/lib/antlr-2.7.7.jar
+++ /dev/null
Binary files differ
diff --git a/tools/signature-tools/lib/stringtemplate.jar b/tools/signature-tools/lib/stringtemplate.jar
deleted file mode 100644
index 8e41531..0000000
--- a/tools/signature-tools/lib/stringtemplate.jar
+++ /dev/null
Binary files differ
diff --git a/tools/signature-tools/sig b/tools/signature-tools/sig
deleted file mode 100755
index 19b57fa..0000000
--- a/tools/signature-tools/sig
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2008 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.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-libdir=`dirname $progdir`/framework
-
-javaOpts=""
-while expr "x$1" : 'x-J' >/dev/null; do
- opt=`expr "$1" : '-J\(.*\)'`
- javaOpts="${javaOpts} -${opt}"
- shift
-done
-
-exec java $javaOpts -classpath $libdir/signature-tools.jar:$libdir/dex-tools.jar:$libdir/stringtemplate.jar:$libdir/antlr-2.7.7.jar signature.Main "$@"
\ No newline at end of file
diff --git a/tools/signature-tools/sig-check b/tools/signature-tools/sig-check
deleted file mode 100755
index 0c1cbce..0000000
--- a/tools/signature-tools/sig-check
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2008 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.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-libdir=`dirname $progdir`/framework
-classpath=$libdir/signature-tools.jar:$libdir/dex-tools.jar:\
-$libdir/stringtemplate.jar:$libdir/antlr-2.7.7.jar
-
-javaOpts=""
-while expr "x$1" : 'x-J' >/dev/null; do
- opt=`expr "$1" : '-J\(.*\)'`
- javaOpts="${javaOpts} -${opt}"
- shift
-done
-
-COREDEX=${ANDROID_PRODUCT_OUT}/../../common/obj/JAVA_LIBRARIES/core_intermediates/classes.dex
-
-if [ ! -f ${COREDEX} ]; then
- echo ERROR: $COREDEX not found
- exit -1;
-fi
-
-sig --compare \
---from sig ${ANDROID_BUILD_TOP}/cts/tools/signature-tools/spec/android.spec \
---name android cupcake reference \
---to dex ${COREDEX} \
---name Android 1.0 \(current build\) \
---out ${ANDROID_BUILD_TOP}/out/delta \
---packages \
-java.beans \
-java.io \
-java.lang \
-java.lang.annotation \
-java.lang.ref \
-java.lang.reflect \
-java.math \
-java.net \
-java.nio \
-java.nio.channels \
-java.nio.channels.spi \
-java.nio.charset \
-java.nio.charset.spi \
-java.security \
-java.security.acl \
-java.security.cert \
-java.security.interfaces \
-java.security.spec \
-java.sql \
-java.text \
-java.util \
-java.util.concurrent \
-java.util.concurrent.atomic \
-java.util.concurrent.locks \
-java.util.jar \
-java.util.logging \
-java.util.prefs \
-java.util.regex \
-java.util.zip \
-javax.crypto \
-javax.crypto.interfaces \
-javax.crypto.spec \
-javax.imageio \
-javax.imageio.event \
-javax.imageio.metadata \
-javax.imageio.plugins.bmp \
-javax.imageio.plugins.jpeg \
-javax.imageio.spi \
-javax.imageio.stream \
-javax.net \
-javax.net.ssl \
-javax.security.auth \
-javax.security.auth.callback \
-javax.security.auth.login \
-javax.security.auth.x500 \
-javax.security.cert \
-javax.sql \
-javax.xml.parsers \
-org.w3c.dom \
-org.xml.sax \
-org.xml.sax.ext \
-org.xml.sax.helpers
diff --git a/tools/signature-tools/sig-create b/tools/signature-tools/sig-create
deleted file mode 100755
index 4049e69..0000000
--- a/tools/signature-tools/sig-create
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2008 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.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-libdir=`dirname $progdir`/framework
-classpath=$libdir/signature-tools.jar:$libdir/dex-tools.jar:\
-$libdir/stringtemplate.jar:$libdir/antlr-2.7.7.jar
-
-javaOpts=""
-while expr "x$1" : 'x-J' >/dev/null; do
- opt=`expr "$1" : '-J\(.*\)'`
- javaOpts="${javaOpts} -${opt}"
- shift
-done
-
-COREDEX=${ANDROID_PRODUCT_OUT}/../../common/obj/JAVA_LIBRARIES/core_intermediates/classes.dex
-
-if [ ! -f ${COREDEX} ]; then
- echo ERROR: $COREDEX not found
- exit -1;
-fi
-
-sig --create dex ${COREDEX} \
---out ${ANDROID_BUILD_TOP}/out/dex \
---name cts_dex_1.0.1 \
---packages \
-java.beans \
-java.io \
-java.lang \
-java.lang.annotation \
-java.lang.ref \
-java.lang.reflect \
-java.math \
-java.net \
-java.nio \
-java.nio.channels \
-java.nio.channels.spi \
-java.nio.charset \
-java.nio.charset.spi \
-java.security \
-java.security.acl \
-java.security.cert \
-java.security.interfaces \
-java.security.spec \
-java.sql \
-java.text \
-java.util \
-java.util.concurrent \
-java.util.concurrent.atomic \
-java.util.concurrent.locks \
-java.util.jar \
-java.util.logging \
-java.util.prefs \
-java.util.regex \
-java.util.zip \
-javax.crypto \
-javax.crypto.interfaces \
-javax.crypto.spec \
-javax.imageio \
-javax.imageio.event \
-javax.imageio.metadata \
-javax.imageio.plugins.bmp \
-javax.imageio.plugins.jpeg \
-javax.imageio.spi \
-javax.imageio.stream \
-javax.net \
-javax.net.ssl \
-javax.security.auth \
-javax.security.auth.callback \
-javax.security.auth.login \
-javax.security.auth.x500 \
-javax.security.cert \
-javax.sql \
-javax.xml.parsers \
-org.w3c.dom \
-org.xml.sax \
-org.xml.sax.ext \
-org.xml.sax.helpers
\ No newline at end of file
diff --git a/tools/signature-tools/spec/android.spec b/tools/signature-tools/spec/android.spec
deleted file mode 100644
index fbbf53a..0000000
--- a/tools/signature-tools/spec/android.spec
+++ /dev/null
Binary files differ
diff --git a/tools/signature-tools/src/signature/Main.java b/tools/signature-tools/src/signature/Main.java
deleted file mode 100644
index 5b1c9ff..0000000
--- a/tools/signature-tools/src/signature/Main.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature;
-
-/**
- * The main entry point for the signature tool. If invoked with
- * <code>--create</code> the call is delegated to
- * {@link signature.converter.Main}. If invoked with <code>--compare</code> the
- * call is delegated to {@link signature.compare.Main}.
- *
- * @see signature.converter.Main
- * @see signature.compare.Main
- */
-public class Main {
-
- private static final String USAGE_MESSAGE = "usage:\n"
- + " sig --create (doclet | dex) sourcefiles --out directory"
- + " --name <name> --packages packageName{ packageName}\n"
- + " sig --compare --from=(doclet | dex | sig) <sourcefiles>"
- + " --name <name> --to=(doclet | dex | sig) <sourcefiles>"
- + " --name <name> --out directory"
- + " --packages packageName{ packageName}\n sig --help";
-
- /**
- * This class is uninstantiable.
- */
- private Main() {
- // This space intentionally left blank.
- }
-
- /**
- * Run!
- */
- public static void main(String[] args) {
- boolean gotCmd = false;
- boolean showUsage = false;
-
- try {
- for (int i = 0; i < args.length; i++) {
- String arg = args[i];
- if (arg.equals("--") || !arg.startsWith("--")) {
- gotCmd = false;
- showUsage = true;
- break;
- }
-
- gotCmd = true;
- if (arg.equals("--create")) {
- signature.converter.Main.main(without(args, i));
- break;
- } else if (arg.equals("--compare")) {
- signature.compare.Main.main(without(args, i));
- break;
- } else if (arg.equals("--version")) {
- version();
- break;
- } else if (arg.equals("--help")) {
- showUsage = true;
- break;
- } else {
- gotCmd = false;
- }
- }
- } catch (UsageException ex) {
- showUsage = true;
- } catch (RuntimeException ex) {
- System.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:");
- ex.printStackTrace();
- System.exit(2);
- } catch (Throwable ex) {
- System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:");
- ex.printStackTrace();
- System.exit(3);
- }
-
- if (!gotCmd) {
- System.err.println("error: no command specified");
- showUsage = true;
- }
-
- if (showUsage) {
- usage();
- System.exit(1);
- }
- }
-
- /**
- * Prints the version message.
- */
- private static void version() {
- System.err.println("android sigtools version " + Version.VERSION);
- System.exit(0);
- }
-
- /**
- * Prints the usage message.
- */
- private static void usage() {
- System.err.println(USAGE_MESSAGE);
- }
-
- /**
- * Returns a copy of the given argument array, but without the indicated
- * element.
- *
- * @param orig
- * non-null; original array
- * @param n
- * which element to omit
- * @return non-null; new array
- */
- private static String[] without(String[] orig, int n) {
- int len = orig.length - 1;
- String[] newa = new String[len];
- System.arraycopy(orig, 0, newa, 0, n);
- System.arraycopy(orig, n + 1, newa, n, len - n);
- return newa;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/UsageException.java b/tools/signature-tools/src/signature/UsageException.java
deleted file mode 100644
index 6cdf9cf..0000000
--- a/tools/signature-tools/src/signature/UsageException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature;
-
-/**
- * Simple exception class used to communicate that the command-line tool should
- * print the usage message.
- */
-@SuppressWarnings("serial")
-public class UsageException extends RuntimeException {
- // This space intentionally left blank.
-}
diff --git a/tools/signature-tools/src/signature/Version.java b/tools/signature-tools/src/signature/Version.java
deleted file mode 100644
index d20e81f..0000000
--- a/tools/signature-tools/src/signature/Version.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature;
-
-/**
- * {@code Version} defines the VERSION constant of the signature tools.
- */
-public class Version {
- /**
- * The program version of the signature tools.
- */
- public static final String VERSION = "0.1";
-}
diff --git a/tools/signature-tools/src/signature/compare/ApiComparator.java b/tools/signature-tools/src/signature/compare/ApiComparator.java
deleted file mode 100644
index 9232d2d..0000000
--- a/tools/signature-tools/src/signature/compare/ApiComparator.java
+++ /dev/null
@@ -1,1705 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IAnnotationElementDelta;
-import signature.compare.model.IAnnotationFieldDelta;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IConstructorDelta;
-import signature.compare.model.IDelta;
-import signature.compare.model.IEnumConstantDelta;
-import signature.compare.model.IFieldDelta;
-import signature.compare.model.IGenericDeclarationDelta;
-import signature.compare.model.IMethodDelta;
-import signature.compare.model.IModifierDelta;
-import signature.compare.model.IPackageDelta;
-import signature.compare.model.IParameterDelta;
-import signature.compare.model.IParameterizedTypeDelta;
-import signature.compare.model.IPrimitiveTypeDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.compare.model.ITypeVariableDefinitionDelta;
-import signature.compare.model.IUpperBoundsDelta;
-import signature.compare.model.IValueDelta;
-import signature.compare.model.IWildcardTypeDelta;
-import signature.compare.model.impl.SigAnnotationDelta;
-import signature.compare.model.impl.SigAnnotationElementDelta;
-import signature.compare.model.impl.SigAnnotationFieldDelta;
-import signature.compare.model.impl.SigApiDelta;
-import signature.compare.model.impl.SigArrayTypeDelta;
-import signature.compare.model.impl.SigClassDefinitionDelta;
-import signature.compare.model.impl.SigClassReferenceDelta;
-import signature.compare.model.impl.SigConstructorDelta;
-import signature.compare.model.impl.SigEnumConstantDelta;
-import signature.compare.model.impl.SigFieldDelta;
-import signature.compare.model.impl.SigGenericDeclarationDelta;
-import signature.compare.model.impl.SigMethodDelta;
-import signature.compare.model.impl.SigModifierDelta;
-import signature.compare.model.impl.SigPackageDelta;
-import signature.compare.model.impl.SigParameterDelta;
-import signature.compare.model.impl.SigParameterizedTypeDelta;
-import signature.compare.model.impl.SigPrimitiveTypeDelta;
-import signature.compare.model.impl.SigTypeDelta;
-import signature.compare.model.impl.SigTypeVariableDefinitionDelta;
-import signature.compare.model.impl.SigTypeVariableReferenceDelta;
-import signature.compare.model.impl.SigUpperBoundsDelta;
-import signature.compare.model.impl.SigValueDelta;
-import signature.compare.model.impl.SigWildcardTypeDelta;
-import signature.compare.model.subst.ClassProjection;
-import signature.compare.model.subst.ViewpointAdapter;
-import signature.model.IAnnotation;
-import signature.model.IAnnotationElement;
-import signature.model.IAnnotationField;
-import signature.model.IApi;
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IExecutableMember;
-import signature.model.IField;
-import signature.model.IGenericDeclaration;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.IParameter;
-import signature.model.IParameterizedType;
-import signature.model.IPrimitiveType;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.IWildcardType;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigAnnotationElement;
-import signature.model.impl.SigArrayType;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-/**
- * {@code ApiComparator} takes two signature models as input and creates a delta
- * model describing the differences between those.
- */
-public class ApiComparator implements IApiComparator {
-
- public IApiDelta compare(IApi from, IApi to) {
- assert from.getVisibility() == to.getVisibility();
-
- Set<IPackage> fromPackages = from.getPackages();
- Set<IPackage> toPackages = to.getPackages();
-
- Set<IPackageDelta> packageDeltas = compareSets(fromPackages,
- toPackages, new SigComparator<IPackage, IPackageDelta>() {
- public IPackageDelta createChangedDelta(IPackage from,
- IPackage to) {
- return comparePackage(from, to);
- }
-
- public IPackageDelta createAddRemoveDelta(IPackage from,
- IPackage to) {
- return new SigPackageDelta(from, to);
- }
-
- public boolean considerEqualElement(IPackage from,
- IPackage to) {
- return from.getName().equals(to.getName());
- }
- });
-
- SigApiDelta delta = null;
- if (packageDeltas != null) {
- delta = new SigApiDelta(from, to);
- delta.setPackageDeltas(packageDeltas);
- }
- return delta;
- }
-
- private IPackageDelta comparePackage(IPackage from, IPackage to) {
- assert from.getName().equals(to.getName());
-
- Set<IClassDefinition> fromClasses = from.getClasses();
- Set<IClassDefinition> toClasses = to.getClasses();
-
- Set<IClassDefinitionDelta> classDeltas = compareSets(fromClasses,
- toClasses,
- new SigComparator<IClassDefinition, IClassDefinitionDelta>() {
- public boolean considerEqualElement(IClassDefinition from,
- IClassDefinition to) {
- return sameClassDefinition(from, to);
- }
-
- public IClassDefinitionDelta createChangedDelta(
- IClassDefinition from, IClassDefinition to) {
- return compareClass(from, to);
- }
-
- public IClassDefinitionDelta createAddRemoveDelta(
- IClassDefinition from, IClassDefinition to) {
- return new SigClassDefinitionDelta(from, to);
- }
- });
-
- SigPackageDelta delta = null;
- if (classDeltas != null) {
- delta = new SigPackageDelta(from, to);
- delta.setClassDeltas(classDeltas);
- }
-
- // Annotations
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (delta != null) {
- delta = new SigPackageDelta(from, to);
- }
- delta.setAnnotationDeltas(annotationDeltas);
- }
- return delta;
- }
-
- private IClassDefinitionDelta compareClass(IClassDefinition from,
- IClassDefinition to) {
- assert from.getKind() == to.getKind();
- assert from.getName().equals(to.getName());
- assert from.getPackageName().equals(to.getPackageName());
-
- SigClassDefinitionDelta classDelta = null;
-
- // modifiers
- Set<IModifierDelta> modifierDeltas = compareModifiers(from
- .getModifiers(), to.getModifiers());
- if (modifierDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setModifierDeltas(modifierDeltas);
- }
-
- // super class
- ITypeReferenceDelta<?> superTypeDelta = compareType(from
- .getSuperClass(), to.getSuperClass(), false);
- if (superTypeDelta != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setSuperClassDelta(superTypeDelta);
- }
-
- // interfaces
- Set<ITypeReferenceDelta<?>> interfaceDeltas = compareInterfaces(from,
- to);
- if (interfaceDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setInterfaceDeltas(interfaceDeltas);
- }
-
- // type variables
- Set<ITypeVariableDefinitionDelta> typeVariableDeltas =
- compareTypeVariableSequence(from.getTypeParameters(),
- to.getTypeParameters());
- if (typeVariableDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setTypeVariableDeltas(typeVariableDeltas);
- }
-
- // constructors
- Set<IConstructorDelta> constructorDeltas = compareConstructors(from
- .getConstructors(), to.getConstructors());
- if (constructorDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setConstructorDeltas(constructorDeltas);
- }
-
- // methods
- Set<IMethodDelta> methodDeltas = compareMethods(from, to);
- if (methodDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setMethodDeltas(methodDeltas);
- }
-
- // fields
- Set<IFieldDelta> fieldDeltas = compareFields(from.getFields(), to
- .getFields());
- if (fieldDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setFieldDeltas(fieldDeltas);
- }
-
- // enum constants
- if (from.getKind() == Kind.ENUM) {
- Set<IEnumConstantDelta> enumDeltas = compareEnumConstants(from
- .getEnumConstants(), to.getEnumConstants());
- if (enumDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setEnumConstantDeltas(enumDeltas);
- }
- } else if (from.getKind() == Kind.ANNOTATION) {
- Set<IAnnotationFieldDelta> annotationFieldDeltas =
- compareAnnotationFields(from.getAnnotationFields(),
- to.getAnnotationFields());
- if (annotationFieldDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setAnnotationFieldDeltas(annotationFieldDeltas);
- }
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (classDelta == null) {
- classDelta = new SigClassDefinitionDelta(from, to);
- }
- classDelta.setAnnotationDeltas(annotationDeltas);
- }
- return classDelta;
- }
-
- private Set<ITypeReferenceDelta<?>> compareInterfaces(
- IClassDefinition from, IClassDefinition to) {
- Set<ITypeReference> fromClosure = getInterfaceClosure(from);
- Set<ITypeReference> toClosure = getInterfaceClosure(to);
-
- Set<ITypeReference> fromInterfaces = from.getInterfaces();
- Set<ITypeReference> toInterfaces = to.getInterfaces();
-
- Set<ITypeReferenceDelta<?>> deltas =
- new HashSet<ITypeReferenceDelta<?>>();
-
- // check whether all from interfaces are directly or indirectly
- // implemented by the to method
- for (ITypeReference type : fromInterfaces) {
- if (!containsType(type, toInterfaces)) {
- if (!(containsType(type, toClosure) /*
- * && !containsType(type,
- * toInterfaces)
- */)) {
- deltas.add(new SigTypeDelta<ITypeReference>(type, null));
- }
- }
- }
-
- // check whether all interfaces to are directly or indirectly
- // implemented by the from method
- for (ITypeReference type : toInterfaces) {
- if (!containsType(type, fromInterfaces)) {
- if (!(containsType(type, fromClosure) /*
- * && !containsType(type,
- * fromInterfaces)
- */)) {
- deltas.add(new SigTypeDelta<ITypeReference>(null, type));
- }
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
-
- private boolean containsType(ITypeReference type,
- Set<ITypeReference> setOfTypes) {
- for (ITypeReference other : setOfTypes) {
- if (compareType(type, other, false) == null) {
- return true;
- }
- }
- return false;
- }
-
- private Set<ITypeReference> getInterfaceClosure(IClassDefinition clazz) {
- Set<ITypeReference> closure = new HashSet<ITypeReference>();
- collectInterfaceClosure(ViewpointAdapter.getReferenceTo(clazz),
- closure);
- return closure;
- }
-
- private void collectInterfaceClosure(ITypeReference clazz,
- Set<ITypeReference> closure) {
-
- IClassDefinition classDefinition = getClassDefinition(clazz);
- Set<ITypeReference> interfaces = classDefinition.getInterfaces();
- if (interfaces == null) {
- return;
- }
- for (ITypeReference interfaze : interfaces) {
- closure.add(interfaze);
- }
-
- ITypeReference superclass = classDefinition.getSuperClass();
- if (superclass != null) {
- if (superclass instanceof IParameterizedType) {
- collectInterfaceClosure(((IParameterizedType) superclass)
- .getRawType(), closure);
- } else {
- collectInterfaceClosure(superclass, closure);
- }
- }
- for (ITypeReference interfaze : interfaces) {
- if (interfaze instanceof IParameterizedType) {
- collectInterfaceClosure(((IParameterizedType) interfaze)
- .getRawType(), closure);
- } else {
- collectInterfaceClosure(interfaze, closure);
- }
- }
- }
-
- private Set<IAnnotationDelta> compareAnnotations(Set<IAnnotation> from,
- Set<IAnnotation> to) {
- return compareSets(from, to,
- new SigComparator<IAnnotation, IAnnotationDelta>() {
- public IAnnotationDelta createAddRemoveDelta(
- IAnnotation from, IAnnotation to) {
- return new SigAnnotationDelta(from, to);
- }
-
- public boolean considerEqualElement(IAnnotation from,
- IAnnotation to) {
- return sameClassDefinition(from.getType()
- .getClassDefinition(), to.getType()
- .getClassDefinition());
- }
-
- public IAnnotationDelta createChangedDelta(
- IAnnotation from, IAnnotation to) {
- return compareAnnotation(from, to);
- }
- });
- }
-
- private Set<IAnnotationFieldDelta> compareAnnotationFields(
- Set<IAnnotationField> from, Set<IAnnotationField> to) {
- return compareSets(from, to,
- new SigComparator<IAnnotationField, IAnnotationFieldDelta>() {
- public boolean considerEqualElement(IAnnotationField from,
- IAnnotationField to) {
- return from.getName().equals(to.getName());
- }
-
- public IAnnotationFieldDelta createAddRemoveDelta(
- IAnnotationField from, IAnnotationField to) {
- return new SigAnnotationFieldDelta(from, to);
- }
-
- public IAnnotationFieldDelta createChangedDelta(
- IAnnotationField from, IAnnotationField to) {
- return compareAnnotationField(from, to);
- }
- });
- }
-
- private Set<IEnumConstantDelta> compareEnumConstants(
- Set<IEnumConstant> from, Set<IEnumConstant> to) {
- return compareSets(from, to,
- new SigComparator<IEnumConstant, IEnumConstantDelta>() {
- public boolean considerEqualElement(IEnumConstant from,
- IEnumConstant to) {
- return from.getName().equals(to.getName());
- }
-
- public IEnumConstantDelta createAddRemoveDelta(
- IEnumConstant from, IEnumConstant to) {
- return new SigEnumConstantDelta(from, to);
- }
-
- public IEnumConstantDelta createChangedDelta(
- IEnumConstant from, IEnumConstant to) {
- return compareEnumConstant(from, to);
- }
- });
- }
-
- private Set<IFieldDelta> compareFields(Set<IField> from, Set<IField> to) {
- return compareSets(from, to, new SigComparator<IField, IFieldDelta>() {
- public boolean considerEqualElement(IField from, IField to) {
- return from.getName().equals(to.getName());
- }
-
- public IFieldDelta createAddRemoveDelta(IField from, IField to) {
- return new SigFieldDelta(from, to);
- }
-
- public IFieldDelta createChangedDelta(IField from, IField to) {
- return compareField(from, to);
- }
- });
- }
-
- private Set<IMethodDelta> compareMethods(IClassDefinition from,
- IClassDefinition to) {
- assert from != null;
- assert to != null;
-
- Set<IMethod> toMethods = new HashSet<IMethod>(to.getMethods());
- Set<IMethod> toClosure = getMethodClosure(to);
- Set<IMethod> fromMethods = new HashSet<IMethod>(from.getMethods());
- Set<IMethod> fromClosure = getMethodClosure(from);
-
- Set<IMethodDelta> deltas = new HashSet<IMethodDelta>();
-
- for (IMethod method : fromMethods) {
- IMethod compatibleMethod = findCompatibleMethod(method, toMethods);
- if (compatibleMethod == null) {
- compatibleMethod = findCompatibleMethod(method, toClosure);
- if (compatibleMethod == null) {
- deltas.add(new SigMethodDelta(method, null));
- }
- }
-
- if (compatibleMethod != null) {
- IMethodDelta delta = compareMethod(method, compatibleMethod);
- if (delta != null) {
- deltas.add(delta);
- }
- }
- }
-
- for (IMethod method : toMethods) {
- IMethod compatibleMethod = findCompatibleMethod(method, fromMethods);
- if (compatibleMethod == null) {
- compatibleMethod = findCompatibleMethod(method, fromClosure);
- if (compatibleMethod == null) {
- deltas.add(new SigMethodDelta(null, method));
- }
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
- private IMethod findCompatibleMethod(IMethod method, Set<IMethod> set) {
- for (IMethod methodFromSet : set) {
- if (equalsSignature(method, methodFromSet)) {
- return methodFromSet;
- }
- }
- return null;
- }
-
-
- private Set<IMethod> getMethodClosure(IClassDefinition clazz) {
- Set<IMethod> closure = new HashSet<IMethod>();
- collectMethods(new ClassProjection(clazz,
- new HashMap<ITypeVariableDefinition, ITypeReference>()),
- closure);
- return closure;
- }
-
- private void collectMethods(IClassDefinition clazz, Set<IMethod> closure) {
- if (clazz == null) {
- return;
- }
- if (clazz.getMethods() != null) {
- closure.addAll(clazz.getMethods());
- }
- if (clazz.getSuperClass() != null) {
- collectMethods(getClassDefinition(clazz.getSuperClass()), closure);
- }
- if (clazz.getInterfaces() != null) {
- for (ITypeReference interfaze : clazz.getInterfaces()) {
- collectMethods(getClassDefinition(interfaze), closure);
- }
- }
- }
-
- private Set<IConstructorDelta> compareConstructors(Set<IConstructor> from,
- Set<IConstructor> to) {
- return compareSets(from, to,
- new SigComparator<IConstructor, IConstructorDelta>() {
- public boolean considerEqualElement(IConstructor from,
- IConstructor to) {
- return equalsSignature(from, to);
- }
-
- public IConstructorDelta createAddRemoveDelta(
- IConstructor from, IConstructor to) {
- return new SigConstructorDelta(from, to);
- }
-
- public IConstructorDelta createChangedDelta(
- IConstructor from, IConstructor to) {
- return compareConstructor(from, to);
- }
- });
- }
-
- // compares names and parameter types
- private boolean equalsSignature(IExecutableMember from,
- IExecutableMember to) {
- if (from.getName().equals(to.getName())) {
- return compareTypeSequence(getParameterList(from.getParameters()),
- getParameterList(to.getParameters()), true) == null;
- }
- return false;
- }
-
- private List<ITypeReference> getParameterList(List<IParameter> parameters) {
- List<ITypeReference> parameterTypes = new LinkedList<ITypeReference>();
- for (IParameter parameter : parameters) {
- parameterTypes.add(parameter.getType());
- }
- return parameterTypes;
- }
-
- private IAnnotationDelta compareAnnotation(IAnnotation from,
- IAnnotation to) {
- assert sameClassDefinition(from.getType().getClassDefinition(), to
- .getType().getClassDefinition());
-
- Set<IAnnotationElement> fromAnnotationElement =
- getNormalizedAnnotationElements(from);
- Set<IAnnotationElement> toAnnotationElement =
- getNormalizedAnnotationElements(to);
-
- Set<IAnnotationElementDelta> annotationElementDeltas =
- compareAnnotationElements(
- fromAnnotationElement, toAnnotationElement);
- SigAnnotationDelta delta = null;
-
- if (annotationElementDeltas != null) {
- delta = new SigAnnotationDelta(from, to);
- delta.setAnnotationElementDeltas(annotationElementDeltas);
- }
- return delta;
- }
-
- /**
- * Returns the annotation elements for the given annotation. The returned
- * set contains all declared elements plus all elements with default values.
- *
- * @param annotation
- * the annotation to return the elements for
- * @return the default enriched annotation elements
- */
- private Set<IAnnotationElement> getNormalizedAnnotationElements(
- IAnnotation annotation) {
- Set<IAnnotationElement> elements = new HashSet<IAnnotationElement>(
- annotation.getElements());
-
- Set<String> names = new HashSet<String>();
- for (IAnnotationElement annotationElement : elements) {
- names.add(annotationElement.getDeclaringField().getName());
- }
-
- for (IAnnotationField field : annotation.getType().getClassDefinition()
- .getAnnotationFields()) {
- if (!names.contains(field.getName())) {
- SigAnnotationElement sigAnnotationElement =
- new SigAnnotationElement();
- sigAnnotationElement.setDeclaringField(field);
- sigAnnotationElement.setValue(field.getDefaultValue());
- elements.add(sigAnnotationElement);
- }
- }
- return elements;
- }
-
- private Set<IAnnotationElementDelta> compareAnnotationElements(
- Set<IAnnotationElement> from, Set<IAnnotationElement> to) {
- return compareSets(from, to,
- new SigComparator<IAnnotationElement, IAnnotationElementDelta>() {
- public boolean considerEqualElement(
- IAnnotationElement from, IAnnotationElement to) {
- return from.getDeclaringField().getName().equals(
- to.getDeclaringField().getName());
- }
-
- public IAnnotationElementDelta createAddRemoveDelta(
- IAnnotationElement from, IAnnotationElement to) {
- return new SigAnnotationElementDelta(from, to);
- }
-
- public IAnnotationElementDelta createChangedDelta(
- IAnnotationElement from, IAnnotationElement to) {
- return compareAnnotationElement(from, to);
- }
- });
- }
-
- private IAnnotationElementDelta compareAnnotationElement(
- IAnnotationElement from, IAnnotationElement to) {
- SigAnnotationElementDelta delta = null;
- SigValueDelta valueDelta = compareValue(from.getValue(), to.getValue());
-
- if (valueDelta != null) {
- delta = new SigAnnotationElementDelta(from, to);
- delta.setValueDelta(valueDelta);
- }
- return delta;
- }
-
- /**
- * Removes the {@link Modifier#ABSTRACT} modifier.
- */
- private Set<Modifier> prepareMethodModifiers(IMethod method) {
- Set<Modifier> modifierCopy = new HashSet<Modifier>(method
- .getModifiers());
- modifierCopy.remove(Modifier.ABSTRACT);
- return modifierCopy;
- }
-
- private IMethodDelta compareMethod(IMethod from, IMethod to) {
- assert from != null && to != null;
-
- SigMethodDelta methodDelta = null;
- Set<IModifierDelta> modiferDeltas = compareModifiers(
- prepareMethodModifiers(from), prepareMethodModifiers(to));
- if (modiferDeltas != null) {
- methodDelta = new SigMethodDelta(from, to);
- methodDelta.setModifierDeltas(modiferDeltas);
- }
-
- Set<IParameterDelta> parameterDeltas = compareParameterSequence(from
- .getParameters(), to.getParameters());
- if (parameterDeltas != null) {
- if (methodDelta == null) {
- methodDelta = new SigMethodDelta(from, to);
- }
- methodDelta.setParameterDeltas(parameterDeltas);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (methodDelta == null) {
- methodDelta = new SigMethodDelta(from, to);
- }
- methodDelta.setAnnotationDeltas(annotationDeltas);
- }
-
- Set<ITypeVariableDefinitionDelta> typeParameterDeltas =
- compareTypeVariableSequence(from.getTypeParameters(),
- to.getTypeParameters());
- if (typeParameterDeltas != null) {
- if (methodDelta == null) {
- methodDelta = new SigMethodDelta(from, to);
- }
- methodDelta.setTypeVariableDeltas(typeParameterDeltas);
- }
-
- Set<ITypeReferenceDelta<?>> exceptionDeltas = compareTypes(
- normalizeExceptions(from.getExceptions()),
- normalizeExceptions(to.getExceptions()));
- if (exceptionDeltas != null) {
- if (methodDelta == null) {
- methodDelta = new SigMethodDelta(from, to);
- }
- methodDelta.setExceptionDeltas(exceptionDeltas);
- }
-
- ITypeReferenceDelta<?> returnTypeDelta = compareType(from
- .getReturnType(), to.getReturnType(), false);
- if (returnTypeDelta != null) {
- if (methodDelta == null) {
- methodDelta = new SigMethodDelta(from, to);
- }
- methodDelta.setReturnTypeDelta(returnTypeDelta);
- }
-
- return methodDelta;
- }
-
- // remove runtime exceptions,
- // remove sub types of containing exception
- private Set<ITypeReference> normalizeExceptions(
- Set<ITypeReference> exceptions) {
- Set<ITypeReference> exceptionCopy = new HashSet<ITypeReference>(
- exceptions);
-
- Iterator<ITypeReference> iterator = exceptionCopy.iterator();
- while (iterator.hasNext()) {
- ITypeReference exception = iterator.next();
- if (isRuntimeExceptionOrErrorSubtype(exception)) {
- iterator.remove();
- }
- }
- exceptionCopy = removeSpecializations(exceptionCopy);
- return exceptionCopy;
- }
-
- private Set<ITypeReference> removeSpecializations(
- Set<ITypeReference> exceptions) {
- Set<ITypeReference> exceptionCopy = new HashSet<ITypeReference>(
- exceptions);
- for (ITypeReference type : exceptions) {
- Iterator<ITypeReference> it = exceptionCopy.iterator();
- while (it.hasNext()) {
- ITypeReference subType = it.next();
- if (isSuperClass(getClassDefinition(type),
- getClassDefinition(subType))) {
- it.remove();
- }
- }
- }
- return exceptionCopy;
- }
-
- /**
- * Returns true if superC is a super class of subC.
- */
- private boolean isSuperClass(IClassDefinition superC,
- IClassDefinition subC) {
- if (superC == null || subC == null) {
- return false;
- }
-
- if (subC.getSuperClass() == null) {
- return false;
- } else {
- if (getClassDefinition(subC.getSuperClass()).equals(superC)) {
- return true;
- } else {
- return isSuperClass(superC, getClassDefinition(subC
- .getSuperClass()));
- }
- }
- }
-
- private boolean isSuperInterface(IClassDefinition superClass,
- IClassDefinition subClass) {
- if (superClass == null || subClass == null) {
- return false;
- }
-
- if (subClass.getInterfaces() == null) {
- return false;
- } else {
- if (getClassDefinitions(subClass.getInterfaces()).contains(
- superClass)) {
- return true;
- } else {
- for (ITypeReference subType : subClass.getInterfaces()) {
- if (isSuperInterface(superClass,
- getClassDefinition(subType))) {
- return true;
- }
- }
- return false;
- }
- }
- }
-
- private Set<IClassDefinition> getClassDefinitions(
- Set<ITypeReference> references) {
- Set<IClassDefinition> definitions = new HashSet<IClassDefinition>();
- for (ITypeReference ref : references) {
- definitions.add(getClassDefinition(ref));
- }
- return definitions;
- }
-
- /**
- * Returns null if type is not one of:
- * <ul>
- * <li>IClassReference</li>
- * <li>IParameterizedType</li>
- * </ul>
- */
- private IClassDefinition getClassDefinition(ITypeReference type) {
- assert type != null;
-
- IClassDefinition returnValue = null;
- if (type instanceof IClassReference) {
- returnValue = ((IClassReference) type).getClassDefinition();
- } else if (type instanceof IParameterizedType) {
- returnValue = ((IParameterizedType) type).getRawType()
- .getClassDefinition();
- }
- return returnValue;
- }
-
- private boolean isRuntimeExceptionOrErrorSubtype(ITypeReference exception) {
-
- IClassDefinition clazz = getClassDefinition(exception);
- if (clazz != null) {
- if (isRuntimeExceptionOrError(clazz)) {
- return true;
- } else if (clazz.getSuperClass() != null) {
- return isRuntimeExceptionOrErrorSubtype(clazz.getSuperClass());
- } else {
- return false;
- }
- }
- return false;
- }
-
- private boolean isRuntimeExceptionOrError(IClassDefinition exception) {
- if (exception == null) {
- return false;
- }
- String packageName = exception.getPackageName();
- String className = exception.getName();
-
- if (packageName != null && className != null
- && "java.lang".equals(packageName)) {
- return "RuntimeException".equals(className)
- || "Error".equals(className);
- }
- return false;
- }
-
- private IConstructorDelta compareConstructor(IConstructor from,
- IConstructor to) {
- SigConstructorDelta constructorDelta = null;
- Set<IModifierDelta> modiferDeltas = compareModifiers(from
- .getModifiers(), to.getModifiers());
- if (modiferDeltas != null) {
- constructorDelta = new SigConstructorDelta(from, to);
- constructorDelta.setModifierDeltas(modiferDeltas);
- }
-
- Set<IParameterDelta> parameterDeltas = compareParameterSequence(from
- .getParameters(), to.getParameters());
- if (parameterDeltas != null) {
- if (constructorDelta == null) {
- constructorDelta = new SigConstructorDelta(from, to);
- }
- constructorDelta.setParameterDeltas(parameterDeltas);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (constructorDelta == null) {
- constructorDelta = new SigConstructorDelta(from, to);
- }
- constructorDelta.setAnnotationDeltas(annotationDeltas);
- }
-
- Set<ITypeVariableDefinitionDelta> typeParameterDeltas =
- compareTypeVariableSequence(from.getTypeParameters(),
- to.getTypeParameters());
- if (typeParameterDeltas != null) {
- if (constructorDelta == null) {
- constructorDelta = new SigConstructorDelta(from, to);
- }
- constructorDelta.setTypeVariableDeltas(typeParameterDeltas);
- }
-
- Set<ITypeReferenceDelta<?>> exceptionDeltas = compareTypes(
- normalizeExceptions(from.getExceptions()),
- normalizeExceptions(to.getExceptions()));
- if (exceptionDeltas != null) {
- if (constructorDelta == null) {
- constructorDelta = new SigConstructorDelta(from, to);
- }
- constructorDelta.setExceptionDeltas(exceptionDeltas);
- }
- return constructorDelta;
- }
-
- private Set<IParameterDelta> compareParameterSequence(
- List<IParameter> from, List<IParameter> to) {
- assert from.size() == to.size();
- Set<IParameterDelta> deltas = new HashSet<IParameterDelta>();
- Iterator<IParameter> fromIterator = from.iterator();
- Iterator<IParameter> toIterator = to.iterator();
- while (fromIterator.hasNext() && toIterator.hasNext()) {
- IParameterDelta delta = compareParameter(fromIterator.next(),
- toIterator.next());
- if (delta != null) {
- deltas.add(delta);
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
- private IParameterDelta compareParameter(IParameter from, IParameter to) {
- SigParameterDelta delta = null;
- ITypeReferenceDelta<?> typeDelta = compareType(from.getType(), to
- .getType(), false);
- if (typeDelta != null) {
- if (delta == null) {
- delta = new SigParameterDelta(from, to);
- }
- delta.setTypeDelta(typeDelta);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (delta == null) {
- delta = new SigParameterDelta(from, to);
- }
- delta.setAnnotationDeltas(annotationDeltas);
- }
- return delta;
- }
-
- private Set<ITypeVariableDefinitionDelta> compareTypeVariableSequence(
- List<ITypeVariableDefinition> from,
- List<ITypeVariableDefinition> to) {
- Set<ITypeVariableDefinitionDelta> deltas =
- new HashSet<ITypeVariableDefinitionDelta>();
- if (from.size() != to.size()) {
- for (ITypeVariableDefinition fromVariable : from) {
- deltas.add(new SigTypeVariableDefinitionDelta(fromVariable,
- null));
- }
- for (ITypeVariableDefinition toVariable : to) {
- deltas
- .add(new SigTypeVariableDefinitionDelta(null,
- toVariable));
- }
- }
-
- Iterator<ITypeVariableDefinition> fromIterator = from.iterator();
- Iterator<ITypeVariableDefinition> toIterator = to.iterator();
- while (fromIterator.hasNext() && toIterator.hasNext()) {
- ITypeVariableDefinitionDelta delta = compareTypeVariableDefinition(
- fromIterator.next(), toIterator.next());
- if (delta != null) {
- deltas.add(delta);
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
- private ITypeVariableDefinitionDelta compareTypeVariableDefinition(
- ITypeVariableDefinition from, ITypeVariableDefinition to) {
- IGenericDeclarationDelta declarationDelta = compareGenericDeclaration(
- from, to);
-
- if (declarationDelta != null) {
- SigTypeVariableDefinitionDelta delta =
- new SigTypeVariableDefinitionDelta(from, to);
- delta.setGenericDeclarationDelta(declarationDelta);
- return delta;
- }
- IUpperBoundsDelta upperBoundDelta = compareUpperBounds(from
- .getUpperBounds(), to.getUpperBounds());
-
- if (upperBoundDelta != null) {
- SigTypeVariableDefinitionDelta delta =
- new SigTypeVariableDefinitionDelta(from, to);
- delta.setUpperBoundsDelta(upperBoundDelta);
- return delta;
- }
- return null;
- }
-
- private ITypeReferenceDelta<ITypeVariableReference> compareTypeVariableReference(
- ITypeVariableReference from, ITypeVariableReference to) {
- IGenericDeclarationDelta declarationDelta = compareGenericDeclaration(
- from.getTypeVariableDefinition(), to
- .getTypeVariableDefinition());
- if (declarationDelta != null) {
- SigTypeVariableReferenceDelta delta =
- new SigTypeVariableReferenceDelta(from, to);
- delta.setGenericDeclarationDelta(declarationDelta);
- return delta;
- }
- return null;
- }
-
- private Set<IModifierDelta> compareModifiers(Set<Modifier> from,
- Set<Modifier> to) {
- return compareSets(from, to,
- new SigComparator<Modifier, IModifierDelta>() {
- public boolean considerEqualElement(Modifier from,
- Modifier to) {
- return from.equals(to);
- }
-
- public IModifierDelta createAddRemoveDelta(Modifier from,
- Modifier to) {
- return new SigModifierDelta(from, to);
- }
-
- public IModifierDelta createChangedDelta(Modifier from,
- Modifier to) {
- return null;
- }
- });
- }
-
-
- private IFieldDelta compareField(IField from, IField to) {
- SigFieldDelta fieldDelta = null;
-
- Set<IModifierDelta> modiferDeltas = compareModifiers(from
- .getModifiers(), to.getModifiers());
- if (modiferDeltas != null) {
- fieldDelta = new SigFieldDelta(from, to);
- fieldDelta.setModifierDeltas(modiferDeltas);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (fieldDelta == null) {
- fieldDelta = new SigFieldDelta(from, to);
- }
- fieldDelta.setAnnotationDeltas(annotationDeltas);
- }
-
- ITypeReferenceDelta<?> typeDelta = compareType(from.getType(), to
- .getType(), false);
- if (typeDelta != null) {
- if (fieldDelta == null) {
- fieldDelta = new SigFieldDelta(from, to);
- }
- fieldDelta.setTypeDelta(typeDelta);
- }
- return fieldDelta;
- }
-
- private IEnumConstantDelta compareEnumConstant(IEnumConstant from,
- IEnumConstant to) {
- SigEnumConstantDelta enumConstantDelta = null;
-
- Set<IModifierDelta> modiferDeltas = compareModifiers(from
- .getModifiers(), to.getModifiers());
- if (modiferDeltas != null) {
- enumConstantDelta = new SigEnumConstantDelta(from, to);
- enumConstantDelta.setModifierDeltas(modiferDeltas);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (enumConstantDelta == null) {
- enumConstantDelta = new SigEnumConstantDelta(from, to);
- }
- enumConstantDelta.setAnnotationDeltas(annotationDeltas);
- }
-
- ITypeReferenceDelta<?> typeDelta = compareType(from.getType(), to
- .getType(), false);
- if (typeDelta != null) {
- if (enumConstantDelta == null) {
- enumConstantDelta = new SigEnumConstantDelta(from, to);
- }
- enumConstantDelta.setTypeDelta(typeDelta);
- }
-
- // FIXME ordinal not supported in dex
- // ValueDelta ordinalDelta = compareValue(from.getOrdinal(),
- // to.getOrdinal());
- // if (ordinalDelta != null) {
- // if (enumConstantDelta == null) {
- // enumConstantDelta = new SigEnumConstantDelta(from, to);
- // }
- // enumConstantDelta.setOrdinalDelta(ordinalDelta);
- // }
-
- return enumConstantDelta;
- }
-
- private IAnnotationFieldDelta compareAnnotationField(IAnnotationField from,
- IAnnotationField to) {
- SigAnnotationFieldDelta annotationFieldDelta = null;
-
- Set<IModifierDelta> modiferDeltas = compareModifiers(from
- .getModifiers(), to.getModifiers());
- if (modiferDeltas != null) {
- annotationFieldDelta = new SigAnnotationFieldDelta(from, to);
- annotationFieldDelta.setModifierDeltas(modiferDeltas);
- }
-
- Set<IAnnotationDelta> annotationDeltas = compareAnnotations(from
- .getAnnotations(), to.getAnnotations());
- if (annotationDeltas != null) {
- if (annotationFieldDelta == null) {
- annotationFieldDelta = new SigAnnotationFieldDelta(from, to);
- }
- annotationFieldDelta.setAnnotationDeltas(annotationDeltas);
- }
-
- ITypeReferenceDelta<?> typeDelta = compareType(from.getType(), to
- .getType(), false);
- if (typeDelta != null) {
- if (annotationFieldDelta == null) {
- annotationFieldDelta = new SigAnnotationFieldDelta(from, to);
- }
- annotationFieldDelta.setTypeDelta(typeDelta);
- }
-
- IValueDelta defaultValueDelta = compareValue(from.getDefaultValue(), to
- .getDefaultValue());
- if (defaultValueDelta != null) {
- if (annotationFieldDelta == null) {
- annotationFieldDelta = new SigAnnotationFieldDelta(from, to);
- }
- annotationFieldDelta.setDefaultValueDelta(defaultValueDelta);
- }
-
- return annotationFieldDelta;
- }
-
- private SigValueDelta compareValue(Object from, Object to) {
- // same value
- if (from == null && to == null) {
- return null;
- }
-
- // one of both is null and other is not
- if (from == null || to == null) {
- return new SigValueDelta(from, to);
- }
-
- SigValueDelta delta = null;
- // different types
- if (from.getClass() == to.getClass()) {
- if (from.getClass().isArray()) {
- Object[] fromArray = (Object[]) from;
- Object[] toArray = (Object[]) from;
- if (!Arrays.equals(fromArray, toArray)) {
- delta = new SigValueDelta(from, to);
- }
- } else if (from instanceof IEnumConstant) {
- IEnumConstantDelta enumConstantDelta = compareEnumConstant(
- (IEnumConstant) from, (IEnumConstant) to);
- if (enumConstantDelta != null) {
- delta = new SigValueDelta(from, to);
- }
- } else if (from instanceof IAnnotation) {
- IAnnotationDelta annotationDelta = compareAnnotation(
- (IAnnotation) from, (IAnnotation) to);
- if (annotationDelta != null) {
- delta = new SigValueDelta(from, to);
- }
- } else if (from instanceof IField) {
- IFieldDelta fieldDelta = compareField((IField) from,
- (IField) to);
- if (fieldDelta != null) {
- delta = new SigValueDelta(from, to);
- }
- } else if (from instanceof ITypeReference) {
- ITypeReferenceDelta<? extends ITypeReference> typeDelta =
- compareType((ITypeReference) from, (ITypeReference) to,
- false);
- if (typeDelta != null) {
- delta = new SigValueDelta(from, to);
- }
- } else if (!from.equals(to)) {
- delta = new SigValueDelta(from, to);
- }
-
- } else if (!(from == null && to == null)) {
- delta = new SigValueDelta(from, to);
- }
- return delta;
- }
-
- private boolean considerEqualTypes(ITypeReference from, ITypeReference to) {
- assert from != null && to != null;
-
- if (implementInterface(from, to, IPrimitiveType.class)) {
- return comparePrimitiveType((IPrimitiveType) from,
- (IPrimitiveType) to) == null;
- }
- if (implementInterface(from, to, IClassReference.class)) {
- return sameClassDefinition(((IClassReference) from)
- .getClassDefinition(), ((IClassReference) to)
- .getClassDefinition());
- }
- if (implementInterface(from, to, IArrayType.class)) {
- return considerEqualTypes(((IArrayType) from).getComponentType(),
- ((IArrayType) to).getComponentType());
- }
- if (implementInterface(from, to, IParameterizedType.class)) {
- return compareClassReference(((IParameterizedType) from)
- .getRawType(), ((IParameterizedType) to)
- .getRawType()) == null;
- }
- if (implementInterface(from, to, ITypeVariableReference.class)) {
- return compareTypeVariableReference((ITypeVariableReference) from,
- (ITypeVariableReference) to) == null;
- }
-
- return false;
- }
-
- private Set<ITypeReference> fromComparison = new HashSet<ITypeReference>();
- private Set<ITypeReference> toComparison = new HashSet<ITypeReference>();
-
-
- private boolean areInComparison(ITypeReference from, ITypeReference to) {
- return fromComparison.contains(from) && toComparison.contains(to);
- }
-
- private void markInComparison(ITypeReference from, ITypeReference to) {
- fromComparison.add(from);
- toComparison.add(to);
- }
-
- private void markFinishedComparison(ITypeReference from,
- ITypeReference to) {
- fromComparison.remove(from);
- toComparison.remove(to);
- }
-
- private ITypeReferenceDelta<? extends ITypeReference> compareType(
- ITypeReference from, ITypeReference to, boolean acceptErasedTypes) {
-
- if (from == null && to == null) {
- return null;
- }
- if ((from == null && to != null) || (from != null && to == null)) {
- return new SigTypeDelta<ITypeReference>(from, to);
- }
- if (areInComparison(from, to)) {
- return null;
- }
- try {
- markInComparison(from, to);
-
- if (implementInterface(from, to, IPrimitiveType.class)) {
- return comparePrimitiveType((IPrimitiveType) from,
- (IPrimitiveType) to);
- }
- if (implementInterface(from, to, IClassReference.class)) {
- return compareClassReference((IClassReference) from,
- (IClassReference) to);
- }
- if (implementInterface(from, to, IArrayType.class)) {
- return compareArrayType((IArrayType) from, (IArrayType) to);
- }
- if (implementInterface(from, to, IParameterizedType.class)) {
- return compareParameterizedType((IParameterizedType) from,
- (IParameterizedType) to, acceptErasedTypes);
- }
- if (implementInterface(from, to, ITypeVariableReference.class)) {
- return compareTypeVariableReference(
- (ITypeVariableReference) from,
- (ITypeVariableReference) to);
- }
- if (implementInterface(from, to, IWildcardType.class)) {
- return compareWildcardType((IWildcardType) from,
- (IWildcardType) to);
- }
-
- if (acceptErasedTypes) {
- if (isGeneric(from) && !isGeneric(to)) {
- return compareType(getErasedType(from), to, false);
- }
-
- if (!isGeneric(from) && isGeneric(to)) {
- return compareType(from, getErasedType(to), false);
- }
- }
- return new SigTypeDelta<ITypeReference>(from, to);
- } finally {
- markFinishedComparison(from, to);
- }
- }
-
- private boolean isGeneric(ITypeReference reference) {
- if (reference instanceof IParameterizedType
- || reference instanceof ITypeVariableReference
- || reference instanceof IWildcardType) {
- return true;
- }
- if (reference instanceof IArrayType) {
- return isGeneric(((IArrayType) reference).getComponentType());
- }
- return false;
- }
-
- private ITypeReference getErasedType(ITypeReference reference) {
-
- if (reference instanceof IParameterizedType) {
- return ((IParameterizedType) reference).getRawType();
- }
- if (reference instanceof ITypeVariableReference) {
- ITypeVariableDefinition typeVariableDefinition =
- ((ITypeVariableReference) reference)
- .getTypeVariableDefinition();
- return getErasedType(
- typeVariableDefinition.getUpperBounds().get(0));
- }
- if (reference instanceof IWildcardType) {
- return getErasedType(((IWildcardType) reference).getUpperBounds()
- .get(0));
- }
- if (reference instanceof IArrayType) {
- // FIXME implement with erasure projection?
- return new SigArrayType(getErasedType(((IArrayType) reference)
- .getComponentType()));
- }
- if (reference instanceof IPrimitiveType) {
- return reference;
- }
- if (reference instanceof IClassReference) {
- return reference;
- }
- throw new IllegalArgumentException("Unexpected type: " + reference);
- }
-
- private boolean implementInterface(ITypeReference from, ITypeReference to,
- Class<?> check) {
- return check.isAssignableFrom(from.getClass())
- && check.isAssignableFrom(to.getClass());
- }
-
- private IWildcardTypeDelta compareWildcardType(IWildcardType from,
- IWildcardType to) {
- SigWildcardTypeDelta delta = null;
-
- ITypeReference fromLowerBound = from.getLowerBound();
- ITypeReference toLowerBound = to.getLowerBound();
-
- ITypeReferenceDelta<?> lowerBoundDelta = compareType(fromLowerBound,
- toLowerBound, false);
- if (lowerBoundDelta != null) {
- delta = new SigWildcardTypeDelta(from, to);
- delta.setLowerBoundDelta(lowerBoundDelta);
- }
-
- IUpperBoundsDelta upperBoundsDelta = compareUpperBounds(from
- .getUpperBounds(), to.getUpperBounds());
- if (upperBoundsDelta != null) {
- if (delta == null) {
- delta = new SigWildcardTypeDelta(from, to);
- }
- delta.setUpperBoundDelta(upperBoundsDelta);
- }
- return delta;
- }
-
- private IGenericDeclarationDelta compareGenericDeclaration(
- ITypeVariableDefinition fromVariable,
- ITypeVariableDefinition toVariable) {
- IGenericDeclarationDelta delta = null;
-
- IGenericDeclaration from = fromVariable.getGenericDeclaration();
- IGenericDeclaration to = toVariable.getGenericDeclaration();
-
- if (from != null && to != null) {
-
- if (from.getClass() != to.getClass()) {
- delta = new SigGenericDeclarationDelta(from, to);
- } else if (from instanceof IClassDefinition) {
- IClassDefinition fromDeclaringClass = (IClassDefinition) from;
- IClassDefinition toDeclaringClass = (IClassDefinition) to;
-
- if (!sameClassDefinition(fromDeclaringClass,
- toDeclaringClass)) {
- delta = new SigGenericDeclarationDelta(from, to);
- }
-
- } else if (from instanceof IConstructor) {
- IConstructor fromConstructor = (IConstructor) from;
- IConstructor toConstructor = (IConstructor) from;
-
- String fromConstructorName = fromConstructor.getName();
- String fromClassName = fromConstructor.getDeclaringClass()
- .getQualifiedName();
-
- String toConstructorName = toConstructor.getName();
- String toClassName = toConstructor.getDeclaringClass()
- .getQualifiedName();
-
- if ((!fromConstructorName.equals(toConstructorName))
- || (!fromClassName.equals(toClassName))) {
- delta = new SigGenericDeclarationDelta(from, to);
- }
-
- } else if (from instanceof IMethod) {
- IMethod fromMethod = (IMethod) from;
- IMethod toMethod = (IMethod) from;
-
- String fromConstructorName = fromMethod.getName();
- String fromClassName = fromMethod.getDeclaringClass()
- .getQualifiedName();
-
- String toConstructorName = toMethod.getName();
- String toClassName = toMethod.getDeclaringClass()
- .getQualifiedName();
-
- if ((!fromConstructorName.equals(toConstructorName))
- || (!fromClassName.equals(toClassName))) {
- delta = new SigGenericDeclarationDelta(from, to);
- }
- } else {
- throw new IllegalStateException("Invlaid eclaration site: "
- + from);
- }
-
- // check position
- int fromPosition = getPositionOf(fromVariable, from);
- int toPosition = getPositionOf(toVariable, to);
-
- if (fromPosition != toPosition) {
- delta = new SigGenericDeclarationDelta(from, to);
- }
-
-
- } else {
- // one of both is null
- delta = new SigGenericDeclarationDelta(from, to);
- }
- return delta;
- }
-
- private int getPositionOf(ITypeVariableDefinition variable,
- IGenericDeclaration declaration) {
- return declaration.getTypeParameters().indexOf(variable);
- }
-
- private IUpperBoundsDelta compareUpperBounds(List<ITypeReference> from,
- List<ITypeReference> to) {
- if (from.isEmpty() && to.isEmpty()) {
- return null;
- }
- SigUpperBoundsDelta delta = null;
-
- ITypeReference fromFirstUpperBound = from.get(0);
- ITypeReference toFirstUpperBound = to.get(0);
-
- ITypeReferenceDelta<?> firstUpperBoundDelta = compareType(
- fromFirstUpperBound, toFirstUpperBound, false);
- if (firstUpperBoundDelta != null) {
- delta = new SigUpperBoundsDelta(from, to);
- delta.setFirstUpperBoundDelta(firstUpperBoundDelta);
- } else {
- // normalize
- Set<ITypeReference> normalizedfrom = removeGeneralizations(
- new HashSet<ITypeReference>(from));
- Set<ITypeReference> normalizedto = removeGeneralizations(
- new HashSet<ITypeReference>(to));
-
- Set<ITypeReferenceDelta<?>> remainingUpperBoundsDelta =
- compareTypes(normalizedfrom, normalizedto);
- if (remainingUpperBoundsDelta != null) {
- delta = new SigUpperBoundsDelta(from, to);
- delta.setRemainingUpperBoundDeltas(remainingUpperBoundsDelta);
- }
- }
- return delta;
- }
-
- private Set<ITypeReference> removeGeneralizations(
- Set<ITypeReference> bounds) {
- Set<ITypeReference> boundsCopy = new HashSet<ITypeReference>(bounds);
- for (ITypeReference type : bounds) {
- Iterator<ITypeReference> it = boundsCopy.iterator();
- while (it.hasNext()) {
- ITypeReference superType = it.next();
- if (isSuperClass(getClassDefinition(superType),
- getClassDefinition(type))
- || isSuperInterface(getClassDefinition(superType),
- getClassDefinition(type))) {
- it.remove();
- }
- }
- }
- return boundsCopy;
- }
-
- private IParameterizedTypeDelta compareParameterizedType(
- IParameterizedType from, IParameterizedType to,
- boolean ignoreTypeArguments) {
-
- SigParameterizedTypeDelta delta = null;
- // check raw type
- ITypeReferenceDelta<?> rawTypeDelta = compareType(from.getRawType(), to
- .getRawType(), false);
- if (rawTypeDelta != null) {
- delta = new SigParameterizedTypeDelta(from, to);
- delta.setRawTypeDelta(rawTypeDelta);
- } else {
- // check owner type
- ITypeReferenceDelta<?> ownerTypeDelta = compareType(from
- .getOwnerType(), to.getOwnerType(), false);
- if (ownerTypeDelta != null) {
- delta = new SigParameterizedTypeDelta(from, to);
- delta.setOwnerTypeDelta(ownerTypeDelta);
- } else {
- // check argument type
- if (!ignoreTypeArguments) {
- Set<ITypeReferenceDelta<?>> argumentTypeDeltas =
- compareTypeSequence(from.getTypeArguments(),
- to.getTypeArguments(), false);
- if (argumentTypeDeltas != null) {
- delta = new SigParameterizedTypeDelta(from, to);
- delta.setArgumentTypeDeltas(argumentTypeDeltas);
- }
- }
- }
- }
- return delta;
- }
-
- private Set<ITypeReferenceDelta<? extends ITypeReference>> compareTypeSequence(
- List<ITypeReference> from, List<ITypeReference> to,
- boolean ignoreTypeArguments) {
- Set<ITypeReferenceDelta<?>> deltas =
- new HashSet<ITypeReferenceDelta<?>>();
- if (from.size() != to.size()) {
-
- for (ITypeReference type : from) {
- deltas.add(new SigTypeDelta<ITypeReference>(type, null));
- }
- for (ITypeReference type : to) {
- deltas.add(new SigTypeDelta<ITypeReference>(null, type));
- }
- return deltas;
- }
-
- Iterator<? extends ITypeReference> fromIterator = from.iterator();
- Iterator<? extends ITypeReference> toIterator = to.iterator();
- while (fromIterator.hasNext() && toIterator.hasNext()) {
- ITypeReferenceDelta<?> delta = compareType(fromIterator.next(),
- toIterator.next(), ignoreTypeArguments);
- if (delta != null) {
- deltas.add(delta);
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
- private Set<ITypeReferenceDelta<? extends ITypeReference>> compareTypes(
- Set<ITypeReference> from, Set<ITypeReference> to) {
- return compareSets(from, to,
- new SigComparator<ITypeReference, ITypeReferenceDelta<? extends ITypeReference>>() {
- public ITypeReferenceDelta<? extends ITypeReference> createAddRemoveDelta(
- ITypeReference from, ITypeReference to) {
- return new SigTypeDelta<ITypeReference>(from, to);
- }
-
- public boolean considerEqualElement(ITypeReference from,
- ITypeReference to) {
- return considerEqualTypes(from, to);
- }
-
- public ITypeReferenceDelta<? extends ITypeReference> createChangedDelta(
- ITypeReference from, ITypeReference to) {
- return compareType(from, to, false);
- }
- });
- }
-
- private static interface SigComparator<T, S extends IDelta<? extends T>> {
- boolean considerEqualElement(T from, T to);
-
- S createChangedDelta(T from, T to);
-
- /**
- * If null is returned, it will be ignored.
- */
- S createAddRemoveDelta(T from, T to);
- }
-
-
- private <T, S extends IDelta<? extends T>> Set<S> compareSets(Set<T> from,
- Set<T> to, SigComparator<T, S> comparator) {
-
- Set<T> toCopy = new HashSet<T>(to);
- Set<S> deltas = new HashSet<S>();
-
- for (T fromType : from) {
- Iterator<T> toIterator = toCopy.iterator();
- boolean equals = false;
- boolean hasNext = toIterator.hasNext();
-
- while (hasNext && !equals) {
- T toElement = toIterator.next();
- equals = comparator.considerEqualElement(fromType, toElement);
- if (equals) {
- S compare = comparator.createChangedDelta(fromType,
- toElement);
- if (compare != null) {
- deltas.add(compare);
- }
- }
- hasNext = toIterator.hasNext();
- }
-
- if (equals) {
- toIterator.remove();
- } else {
- S delta = comparator.createAddRemoveDelta(fromType, null);
- if (delta != null) {
- deltas.add(delta);
- }
- }
- }
-
- for (T type : toCopy) {
- S delta = comparator.createAddRemoveDelta(null, type);
- if (delta != null) {
- deltas.add(delta);
- }
- }
- return deltas.isEmpty() ? null : deltas;
- }
-
-
- private ITypeReferenceDelta<?> compareArrayType(IArrayType from,
- IArrayType to) {
- ITypeReferenceDelta<?> componentTypeDelta = compareType(from
- .getComponentType(), to.getComponentType(), false);
- if (componentTypeDelta != null) {
- SigArrayTypeDelta delta = new SigArrayTypeDelta(from, to);
- delta.setComponentTypeDelta(componentTypeDelta);
- return delta;
- }
- return null;
- }
-
- private ITypeReferenceDelta<IClassReference> compareClassReference(
- IClassReference fromRef, IClassReference toRef) {
- IClassDefinition from = fromRef.getClassDefinition();
- IClassDefinition to = toRef.getClassDefinition();
-
- if (!sameClassDefinition(from, to)) {
- return new SigClassReferenceDelta(fromRef, toRef);
- }
- return null;
- }
-
-
- private boolean sameClassDefinition(IClassDefinition from,
- IClassDefinition to) {
- boolean sameName = from.getName().equals(to.getName());
- boolean samePackage = from.getPackageName().equals(to.getPackageName());
-
- Kind fromKind = from.getKind();
- Kind toKind = to.getKind();
- boolean sameKind = (fromKind == null || toKind == null)
- || fromKind.equals(toKind);
-
- return sameName && samePackage && sameKind;
- }
-
- private IPrimitiveTypeDelta comparePrimitiveType(IPrimitiveType from,
- IPrimitiveType to) {
- if (!from.equals(to)) {
- return new SigPrimitiveTypeDelta(from, to);
- }
- return null;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/IApiComparator.java b/tools/signature-tools/src/signature/compare/IApiComparator.java
deleted file mode 100644
index 08ed97f..0000000
--- a/tools/signature-tools/src/signature/compare/IApiComparator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare;
-
-import signature.compare.model.IApiDelta;
-import signature.model.IApi;
-
-/**
- * {@code IApiComparator} defines the functionality of a signature comparator.
- */
-public interface IApiComparator {
-
- /**
- * Returns a difference model which describes the differences from {@code
- * fromApi} to {@code toApi}.
- *
- * @param fromApi
- * differences are computed relative to {@code fromApi}
- * @param toApi
- * the target signature model
- * @return a difference model which describes the differences from {@code
- * fromApi} to {@code toApi}
- */
- IApiDelta compare(IApi fromApi, IApi toApi);
-}
diff --git a/tools/signature-tools/src/signature/compare/Main.java b/tools/signature-tools/src/signature/compare/Main.java
deleted file mode 100644
index 80edb45..0000000
--- a/tools/signature-tools/src/signature/compare/Main.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare;
-
-import signature.UsageException;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IPackageDelta;
-import signature.compare.model.impl.SigDelta;
-import signature.converter.Visibility;
-import signature.converter.dex.DexFactory;
-import signature.converter.doclet.DocletFactory;
-import signature.io.IApiDeltaExternalizer;
-import signature.io.IApiLoader;
-import signature.io.html.HtmlDeltaExternalizer;
-import signature.io.impl.BinaryApi;
-import signature.model.IApi;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Driver class for the --compare option.
- */
-public class Main {
-
- /**
- * <pre>
- * --from=(doclet | dex | sig) <sourcefiles>
- * --name <name>
- * --to=(doclet | dex | sig) <sourcefiles>
- * --name <name>
- * --out directory
- * --packages packageName{ packageName}
- * </pre>
- */
- public static void main(String[] args) throws IOException {
- int at = 0;
-
- if (!"--from".equals(args[at])) {
- throw new UsageException();
- }
- String fromType = args[++at];
-
- boolean hasName = false;
- Set<String> fromFiles = new HashSet<String>();
- ++at;
- for (/* at */; at < args.length; at++) {
- if ("--name".equals(args[at])) {
- hasName = true;
- break;
- }
- if ("--to".equals(args[at])) {
- break;
- }
- fromFiles.add(args[at]);
- }
-
- String nameFrom = null;
- if (hasName) {
- nameFrom = "";
- if (!"--name".equals(args[at])) {
- throw new UsageException();
- }
- ++at;
- for (/* at */; at < args.length; at++) {
- if ("--to".equals(args[at])) {
- break;
- }
- nameFrom += args[at];
- nameFrom += " ";
- }
- nameFrom = nameFrom.trim();
- }
-
- if (!"--to".equals(args[at])) {
- throw new UsageException();
- }
- String toType = args[++at];
-
- hasName = false;
- Set<String> toFiles = new HashSet<String>();
- ++at;
- for (/* at */; at < args.length; at++) {
- if ("--name".equals(args[at])) {
- hasName = true;
- break;
- }
- if ("--out".equals(args[at])) {
- break;
- }
- toFiles.add(args[at]);
- }
-
- String nameTo = null;
- if (hasName) {
- nameTo = "";
- if (!"--name".equals(args[at])) {
- throw new UsageException();
- }
- ++at;
- for (/* at */; at < args.length; at++) {
- if ("--out".equals(args[at])) {
- break;
- }
- nameTo += args[at];
- nameTo += " ";
- }
- nameTo = nameTo.trim();
- }
-
- if (!"--out".equals(args[at])) {
- throw new UsageException();
- }
- String output = args[++at];
-
- if (!"--packages".equals(args[++at])) {
- throw new UsageException();
- }
- Set<String> packages = new HashSet<String>();
- ++at;
- for (/* at */; at < args.length; at++) {
- packages.add(args[at]);
- }
-
- IApiComparator comparator = new ApiComparator();
- IApi fromApi = getApi(fromType, nameFrom, fromFiles, packages);
- IApi toApi = getApi(toType, nameTo, toFiles, packages);
-
- IApiDeltaExternalizer externalizer = new HtmlDeltaExternalizer();
- System.out.println("Writing delta report to " + output);
- IApiDelta delta = comparator.compare(fromApi, toApi);
- if (delta == null) {
- delta = new EmptyDelta(fromApi, toApi);
- }
-
- externalizer.externalize(output, delta);
- }
-
- private static class EmptyDelta extends SigDelta<IApi> implements
- IApiDelta {
- public EmptyDelta(IApi from, IApi to) {
- super(from, to);
- }
-
- public Set<IPackageDelta> getPackageDeltas() {
- return Collections.emptySet();
- }
- }
-
- private static IApi getApi(String specType, String name,
- Set<String> fileNames, Set<String> packageNames) throws
- IOException {
- System.out.println("Loading " + name + " of type " + specType
- + " from " + fileNames);
- IApiLoader factory = null;
- if ("doclet".equals(specType)) {
- checkName(name);
- factory = new DocletFactory();
- } else if ("dex".equals(specType)) {
- checkName(name);
- factory = new DexFactory();
- } else if ("sig".equals(specType)) {
- factory = new BinaryApi();
- } else {
- throw new UsageException();
- }
- return factory.loadApi(name, Visibility.PROTECTED, fileNames,
- packageNames);
- }
-
- private static void checkName(String name) {
- if (name == null) {
- throw new UsageException();
- }
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/DeltaType.java b/tools/signature-tools/src/signature/compare/model/DeltaType.java
deleted file mode 100644
index a3aad2c..0000000
--- a/tools/signature-tools/src/signature/compare/model/DeltaType.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-/**
- * {@code DeltaType} defines the three possible types of a delta.
- */
-public enum DeltaType {
- /**
- * States that an element was added to the toApi.
- */
- ADDED,
- /**
- * States that an element was removed from the toApi.
- */
- REMOVED,
- /**
- * States that an element changed.
- */
- CHANGED
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IAnnotatableElementDelta.java b/tools/signature-tools/src/signature/compare/model/IAnnotatableElementDelta.java
deleted file mode 100644
index dd41c60..0000000
--- a/tools/signature-tools/src/signature/compare/model/IAnnotatableElementDelta.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-/**
- * {@code IAnnotatableElementDelta} is the common base interface for deltas
- * which may have {@link IAnnotationDelta}s.
- */
-public interface IAnnotatableElementDelta {
-
- /**
- * Returns a set of annotation deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of annotation deltas, maybe {@code null}
- */
- Set<IAnnotationDelta> getAnnotationDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IAnnotationDelta.java b/tools/signature-tools/src/signature/compare/model/IAnnotationDelta.java
deleted file mode 100644
index 2e29358..0000000
--- a/tools/signature-tools/src/signature/compare/model/IAnnotationDelta.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IAnnotation;
-
-/**
- * {@code IAnnotationDelta} models the delta between two {@link IAnnotation}
- * instances.
- */
-public interface IAnnotationDelta extends IDelta<IAnnotation> {
-
- /**
- * Returns a set of annotation element deltas or {@code null} if no deltas
- * are available.
- *
- * @return a set of annotation element deltas, maybe {@code null}
- */
- Set<IAnnotationElementDelta> getAnnotationElementDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IAnnotationElementDelta.java b/tools/signature-tools/src/signature/compare/model/IAnnotationElementDelta.java
deleted file mode 100644
index 4355fdb..0000000
--- a/tools/signature-tools/src/signature/compare/model/IAnnotationElementDelta.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IAnnotationElement;
-
-/**
- * {@code IAnnotationElementDelta} models the delta between two
- * {@link IAnnotationElement} instances.
- */
-public interface IAnnotationElementDelta extends IDelta<IAnnotationElement> {
-
- /**
- * Returns a value delta or {@code null} if no delta is available.
- *
- * @return a value delta, maybe {@code null}
- */
- IValueDelta getValueDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IAnnotationFieldDelta.java b/tools/signature-tools/src/signature/compare/model/IAnnotationFieldDelta.java
deleted file mode 100644
index 223072a..0000000
--- a/tools/signature-tools/src/signature/compare/model/IAnnotationFieldDelta.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IAnnotationField;
-
-/**
- * {@code IAnnotationFieldDelta} models the delta between two
- * {@link IAnnotationField} instances.
- */
-public interface IAnnotationFieldDelta extends IMemberDelta<IAnnotationField> {
-
- /**
- * Returns the default value delta or {@code null} if no delta is available.
- *
- * @return the default value delta, maybe {@code null}
- */
- IValueDelta getDefaultValueDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IApiDelta.java b/tools/signature-tools/src/signature/compare/model/IApiDelta.java
deleted file mode 100644
index 78a8c34..0000000
--- a/tools/signature-tools/src/signature/compare/model/IApiDelta.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IApi;
-
-/**
- * {@code IApiDelta} models the delta between two {@link IApi} instances.
- */
-public interface IApiDelta extends IDelta<IApi> {
-
- /**
- * Returns a set of package deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of package deltas, maybe {@code null}
- */
- Set<IPackageDelta> getPackageDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IArrayTypeDelta.java b/tools/signature-tools/src/signature/compare/model/IArrayTypeDelta.java
deleted file mode 100644
index bb29bcd..0000000
--- a/tools/signature-tools/src/signature/compare/model/IArrayTypeDelta.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IArrayType;
-
-/**
- * {@code IArrayTypeDelta} models the delta between two {@link IArrayType}
- * instances.
- */
-public interface IArrayTypeDelta extends ITypeReferenceDelta<IArrayType> {
-
- /**
- * Returns a component type delta or {@code null} if no delta is available.
- *
- * @return a component type delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getComponentTypeDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IClassDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/IClassDefinitionDelta.java
deleted file mode 100644
index 5cbaf9b..0000000
--- a/tools/signature-tools/src/signature/compare/model/IClassDefinitionDelta.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IClassDefinition;
-
-/**
- * {@code IClassDefinitionDelta} models the delta between two
- * {@link IClassDefinition} instances.
- */
-public interface IClassDefinitionDelta extends
- ITypeDefinitionDelta<IClassDefinition>, IAnnotatableElementDelta,
- ITypeVariableDeltas {
-
- /**
- * Returns a set of field deltas or {@code null} if no deltas are available.
- *
- * @return a set of field deltas, maybe {@code null}
- */
- Set<IFieldDelta> getFieldDeltas();
-
- /**
- * Returns a set of enum constant deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of enum constant deltas, maybe {@code null}
- */
- Set<IEnumConstantDelta> getEnumConstantDeltas();
-
- /**
- * Returns a set of annotation field deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of annotation field deltas, maybe {@code null}
- */
- Set<IAnnotationFieldDelta> getAnnotationFieldDeltas();
-
- /**
- * Returns a set of method deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of method deltas, maybe {@code null}
- */
- Set<IMethodDelta> getMethodDeltas();
-
- /**
- * Returns a set of constructor deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of constructor deltas, maybe {@code null}
- */
- Set<IConstructorDelta> getConstructorDeltas();
-
- /**
- * Returns a set of modifier deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of modifier deltas, maybe {@code null}
- */
- Set<IModifierDelta> getModifierDeltas();
-
- /**
- * Returns a super class delta or {@code null} if no delta is available.
- *
- * @return a super class delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getSuperClassDelta();
-
- /**
- * Returns a set of interface deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of interface deltas, maybe {@code null}
- */
- Set<ITypeReferenceDelta<?>> getInterfaceDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IConstructorDelta.java b/tools/signature-tools/src/signature/compare/model/IConstructorDelta.java
deleted file mode 100644
index 64ba993..0000000
--- a/tools/signature-tools/src/signature/compare/model/IConstructorDelta.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IConstructor;
-
-/**
- * {@code IConstructorDelta} models the delta between two {@link IConstructor}
- * instances.
- */
-public interface IConstructorDelta extends
- IExecutableMemberDelta<IConstructor> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IDelta.java b/tools/signature-tools/src/signature/compare/model/IDelta.java
deleted file mode 100644
index bd94388..0000000
--- a/tools/signature-tools/src/signature/compare/model/IDelta.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-/**
- * {@code IDelta} is the common base interface for all delta model elements. It
- * describes a delta from a "from" element to a "to" element.
- *
- * @param <T>
- * the type of the compared elements
- */
-public interface IDelta<T> {
-
- /**
- * Returns the type of this delta.
- *
- * @return the type of this delta
- */
- DeltaType getType();
-
- /**
- * Returns the "from" element. Is null if type is {@link DeltaType#ADDED}
- *
- * @return the "from" element
- */
- T getFrom();
-
- /**
- * Returns the "to" element. Is null if type is {@link DeltaType#REMOVED}
- *
- * @return the "to" element
- */
- T getTo();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IEnumConstantDelta.java b/tools/signature-tools/src/signature/compare/model/IEnumConstantDelta.java
deleted file mode 100644
index 6590c5a..0000000
--- a/tools/signature-tools/src/signature/compare/model/IEnumConstantDelta.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IEnumConstant;
-
-/**
- * {@code IEnumConstantDelta} models the delta between two {@link IEnumConstant}
- * instances.
- */
-public interface IEnumConstantDelta extends IMemberDelta<IEnumConstant> {
- IValueDelta getOrdinalDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IExecutableMemberDelta.java b/tools/signature-tools/src/signature/compare/model/IExecutableMemberDelta.java
deleted file mode 100644
index 30f7038..0000000
--- a/tools/signature-tools/src/signature/compare/model/IExecutableMemberDelta.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IExecutableMember;
-
-/**
- * {@code IExecutableMemberDelta} models the delta between two
- * {@link IExecutableMember} instances.
- */
-public interface IExecutableMemberDelta<T extends IExecutableMember> extends
- IDelta<T>, ITypeVariableDeltas, IAnnotatableElementDelta {
-
- /**
- * Returns a set of modifier deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of modifier deltas, maybe {@code null}
- */
- Set<IModifierDelta> getModifierDeltas();
-
- /**
- * Returns a set of exception deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of exception deltas, maybe {@code null}
- */
- Set<ITypeReferenceDelta<?>> getExceptionDeltas();
-
- /**
- * Returns a set of parameter deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of parameter deltas, maybe {@code null}
- */
- Set<IParameterDelta> getParameterDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IFieldDelta.java b/tools/signature-tools/src/signature/compare/model/IFieldDelta.java
deleted file mode 100644
index ab9bf76..0000000
--- a/tools/signature-tools/src/signature/compare/model/IFieldDelta.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IField;
-
-/**
- * {@code IFieldDelta} models the delta between two {@link IField} instances.
- */
-public interface IFieldDelta extends IMemberDelta<IField> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IGenericDeclarationDelta.java b/tools/signature-tools/src/signature/compare/model/IGenericDeclarationDelta.java
deleted file mode 100644
index 5cd518c..0000000
--- a/tools/signature-tools/src/signature/compare/model/IGenericDeclarationDelta.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IGenericDeclaration;
-
-/**
- * {@code IGenericDeclarationDelta} models the delta between two
- * {@link IGenericDeclaration} instances.
- */
-public interface IGenericDeclarationDelta extends IDelta<IGenericDeclaration> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IMemberDelta.java b/tools/signature-tools/src/signature/compare/model/IMemberDelta.java
deleted file mode 100644
index df78307..0000000
--- a/tools/signature-tools/src/signature/compare/model/IMemberDelta.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IField;
-
-/**
- * {@code IMemberDelta} models the delta between two {@link IField} subclass
- * instances.
- */
-public interface IMemberDelta<T extends IField> extends IDelta<T>,
- IAnnotatableElementDelta {
-
- /**
- * Returns a type delta or {@code null} if no delta is available.
- *
- * @return a type delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getTypeDelta();
-
- /**
- * Returns a set of modifier deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of modifier deltas, maybe {@code null}
- */
- Set<IModifierDelta> getModifierDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IMethodDelta.java b/tools/signature-tools/src/signature/compare/model/IMethodDelta.java
deleted file mode 100644
index 3e94d26..0000000
--- a/tools/signature-tools/src/signature/compare/model/IMethodDelta.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IMethod;
-
-/**
- * {@code IMethodDelta} models the delta between two {@link IMethod} subclass
- * instances.
- */
-public interface IMethodDelta extends IExecutableMemberDelta<IMethod> {
-
- /**
- * Returns a return type delta or {@code null} if no delta is available.
- *
- * @return a return type delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getReturnTypeDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IModifierDelta.java b/tools/signature-tools/src/signature/compare/model/IModifierDelta.java
deleted file mode 100644
index 4553e10..0000000
--- a/tools/signature-tools/src/signature/compare/model/IModifierDelta.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.Modifier;
-
-/**
- * {@code IModifierDelta} models the delta between two {@link Modifier}
- * instances.
- */
-public interface IModifierDelta extends IDelta<Modifier> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IPackageDelta.java b/tools/signature-tools/src/signature/compare/model/IPackageDelta.java
deleted file mode 100644
index 8c697c3..0000000
--- a/tools/signature-tools/src/signature/compare/model/IPackageDelta.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IPackage;
-
-/**
- * {@code IPackageDelta} models the delta between two {@link IPackage}
- * instances.
- */
-public interface IPackageDelta extends IDelta<IPackage>,
- IAnnotatableElementDelta {
-
- /**
- * Returns a set of class definition deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of class definition deltas, maybe {@code null}
- */
- Set<IClassDefinitionDelta> getClassDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IParameterDelta.java b/tools/signature-tools/src/signature/compare/model/IParameterDelta.java
deleted file mode 100644
index b2a6a80..0000000
--- a/tools/signature-tools/src/signature/compare/model/IParameterDelta.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IParameter;
-
-/**
- * {@code IParameterDelta} models the delta between two {@link IParameter}
- * instances.
- */
-public interface IParameterDelta extends IDelta<IParameter>,
- IAnnotatableElementDelta {
-
- /**
- * Returns a parameter type delta or {@code null} if no delta is available.
- *
- * @return a parameter type delta, maybe {@code null}
- */
- public ITypeReferenceDelta<?> getTypeDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IParameterizedTypeDelta.java b/tools/signature-tools/src/signature/compare/model/IParameterizedTypeDelta.java
deleted file mode 100644
index be54a01..0000000
--- a/tools/signature-tools/src/signature/compare/model/IParameterizedTypeDelta.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-import signature.model.IParameterizedType;
-
-/**
- * {@code IParameterizedTypeDelta} models the delta between two
- * {@link IParameterizedType} instances.
- */
-public interface IParameterizedTypeDelta extends
- ITypeReferenceDelta<IParameterizedType> {
-
- /**
- * Returns a raw type delta or {@code null} if no delta is available.
- *
- * @return a raw type delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getRawTypeDelta();
-
- /**
- * Returns a owner type delta or {@code null} if no delta is available.
- *
- * @return a owner type delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getOwnerTypeDelta();
-
- /**
- * Returns a set of argument type deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of argument type deltas, maybe {@code null}
- */
- Set<ITypeReferenceDelta<?>> getArgumentTypeDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IPrimitiveTypeDelta.java b/tools/signature-tools/src/signature/compare/model/IPrimitiveTypeDelta.java
deleted file mode 100644
index f729435..0000000
--- a/tools/signature-tools/src/signature/compare/model/IPrimitiveTypeDelta.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IPrimitiveType;
-
-/**
- * {@code IPrimitiveTypeDelta} models the delta between two
- * {@link IPrimitiveType} instances.
- */
-public interface IPrimitiveTypeDelta extends
- ITypeReferenceDelta<IPrimitiveType> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/ITypeDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/ITypeDefinitionDelta.java
deleted file mode 100644
index 932cc39..0000000
--- a/tools/signature-tools/src/signature/compare/model/ITypeDefinitionDelta.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.ITypeDefinition;
-
-/**
- * {@code ITypeDefinitionDelta} is the common base interface for deltas which
- * model differences between type definitions.
- */
-public interface ITypeDefinitionDelta<T extends ITypeDefinition> extends
- IDelta<T> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/ITypeReferenceDelta.java b/tools/signature-tools/src/signature/compare/model/ITypeReferenceDelta.java
deleted file mode 100644
index fba52f0..0000000
--- a/tools/signature-tools/src/signature/compare/model/ITypeReferenceDelta.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.ITypeReference;
-
-/**
- * {@code ITypeReferenceDelta} is the common base interface for deltas which
- * model differences between type references.
- */
-public interface ITypeReferenceDelta<T extends ITypeReference> extends
- IDelta<T> {
-}
diff --git a/tools/signature-tools/src/signature/compare/model/ITypeVariableDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/ITypeVariableDefinitionDelta.java
deleted file mode 100644
index 1e8f3cd..0000000
--- a/tools/signature-tools/src/signature/compare/model/ITypeVariableDefinitionDelta.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.ITypeVariableDefinition;
-
-/**
- * {@code ITypeVariableDefinitionDelta} models the delta between two
- * {@link ITypeVariableDefinition} instances.
- */
-public interface ITypeVariableDefinitionDelta extends
- ITypeDefinitionDelta<ITypeVariableDefinition> {
-
- /**
- * Returns an upper bound delta or {@code null} if no delta is available.
- *
- * @return an upper bound delta, maybe {@code null}
- */
- IUpperBoundsDelta getUpperBoundsDelta();
-
- /**
- * Returns a generic declaration delta or {@code null} if no delta is
- * available.
- *
- * @return a generic declaration delta, maybe {@code null}
- */
- IGenericDeclarationDelta getGenericDeclarationDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/ITypeVariableDeltas.java b/tools/signature-tools/src/signature/compare/model/ITypeVariableDeltas.java
deleted file mode 100644
index a88ea30..0000000
--- a/tools/signature-tools/src/signature/compare/model/ITypeVariableDeltas.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.Set;
-
-/**
- * Common interface for all deltas which may have {@code
- * ITypeVariableDefinitionDelta}s. Type variable deltas can occur, where type
- * variables can be defined. On classes, constructors and methods.
- *
- * @see IClassDefinitionDelta
- * @see IExecutableMemberDelta (common super interface of the following two
- * interfaces)
- * @see IConstructorDelta
- * @see IMethodDelta
- */
-public interface ITypeVariableDeltas {
-
- /**
- * Returns a set of type variable deltas or {@code null} if no deltas are
- * available.
- *
- * @return a set of type variable deltas, maybe {@code null}
- */
- Set<ITypeVariableDefinitionDelta> getTypeVariableDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IUpperBoundsDelta.java b/tools/signature-tools/src/signature/compare/model/IUpperBoundsDelta.java
deleted file mode 100644
index 44bd39a..0000000
--- a/tools/signature-tools/src/signature/compare/model/IUpperBoundsDelta.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import java.util.List;
-import java.util.Set;
-
-import signature.model.ITypeReference;
-
-/**
- * {@code IUpperBoundsDelta} models the delta between two {@link List
- * <ITypeReference>} instances.
- * <p>
- * This interface is aware, that for the first argument, the order of the upper
- * bounds is relevant (for erasure).
- */
-public interface IUpperBoundsDelta extends IDelta<List<ITypeReference>> {
-
- /**
- * Returns the upper bound delta of the first upper bound or {@code null} if
- * no delta is available.
- *
- * @return the upper bound delta of the first upper bound, maybe {@code
- * null}
- */
- ITypeReferenceDelta<?> getFirstUpperBoundDelta();
-
- /**
- * Returns a set of remaining upper bound deltas or {@code null} if no
- * deltas are available.
- *
- * @return a set of remaining upper bound deltas, maybe {@code null}
- */
- Set<ITypeReferenceDelta<?>> getRemainingUpperBoundDeltas();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/IValueDelta.java b/tools/signature-tools/src/signature/compare/model/IValueDelta.java
deleted file mode 100644
index abd1f59..0000000
--- a/tools/signature-tools/src/signature/compare/model/IValueDelta.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-
-/**
- * {@code IValueDelta} models the delta between two
- * {@link Object} instances.
- */
-public interface IValueDelta extends IDelta<Object> {}
diff --git a/tools/signature-tools/src/signature/compare/model/IWildcardTypeDelta.java b/tools/signature-tools/src/signature/compare/model/IWildcardTypeDelta.java
deleted file mode 100644
index 1fda09c..0000000
--- a/tools/signature-tools/src/signature/compare/model/IWildcardTypeDelta.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model;
-
-import signature.model.IWildcardType;
-
-/**
- * {@code IWildcardTypeDelta} models the delta between two
- * {@link IWildcardType} instances.
- */
-public interface IWildcardTypeDelta extends ITypeReferenceDelta<IWildcardType> {
-
- /**
- * Returns the upper bound delta or {@code null} if no delta is available.
- *
- * @return the upper bound delta, maybe {@code null}
- */
- IUpperBoundsDelta getUpperBoundDelta();
-
- /**
- * Returns the lower bound delta or {@code null} if no delta is available.
- *
- * @return the lower bound delta, maybe {@code null}
- */
- ITypeReferenceDelta<?> getLowerBoundDelta();
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationDelta.java
deleted file mode 100644
index 78e515f..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationDelta.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.Set;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IAnnotationElementDelta;
-import signature.model.IAnnotation;
-
-public class SigAnnotationDelta extends SigDelta<IAnnotation> implements
- IAnnotationDelta {
-
- private Set<IAnnotationElementDelta> annotationElementDeltas;
-
- public SigAnnotationDelta(IAnnotation from, IAnnotation to) {
- super(from, to);
- }
-
- public Set<IAnnotationElementDelta> getAnnotationElementDeltas() {
- return annotationElementDeltas;
- }
-
- public void setAnnotationElementDeltas(
- Set<IAnnotationElementDelta> annotationElementDeltas) {
- this.annotationElementDeltas = annotationElementDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationElementDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationElementDelta.java
deleted file mode 100644
index cc7a6fc..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationElementDelta.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IAnnotationElementDelta;
-import signature.compare.model.IValueDelta;
-import signature.model.IAnnotationElement;
-
-public class SigAnnotationElementDelta extends SigDelta<IAnnotationElement>
- implements IAnnotationElementDelta {
-
- private IValueDelta valueDelta;
-
- public SigAnnotationElementDelta(IAnnotationElement from,
- IAnnotationElement to) {
- super(from, to);
- }
-
- public IValueDelta getValueDelta() {
- return valueDelta;
- }
-
- public void setValueDelta(IValueDelta valueDelta) {
- this.valueDelta = valueDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationFieldDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationFieldDelta.java
deleted file mode 100644
index 90fcd7b..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigAnnotationFieldDelta.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IAnnotationFieldDelta;
-import signature.compare.model.IValueDelta;
-import signature.model.IAnnotationField;
-
-public class SigAnnotationFieldDelta extends SigMemberDelta<IAnnotationField>
- implements IAnnotationFieldDelta {
-
- private IValueDelta defaultValueDelta;
-
- public SigAnnotationFieldDelta(IAnnotationField from, IAnnotationField to) {
- super(from, to);
- }
-
- public IValueDelta getDefaultValueDelta() {
- return defaultValueDelta;
- }
-
- public void setDefaultValueDelta(IValueDelta valueDelta) {
- this.defaultValueDelta = valueDelta;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigApiDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigApiDelta.java
deleted file mode 100644
index bc2bd56..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigApiDelta.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IPackageDelta;
-import signature.model.IApi;
-
-import java.util.Set;
-
-public class SigApiDelta extends SigDelta<IApi> implements IApiDelta {
-
- private Set<IPackageDelta> packageDeltas;
-
- public SigApiDelta(IApi from, IApi to) {
- super(from, to);
- }
-
- public Set<IPackageDelta> getPackageDeltas() {
- return packageDeltas;
- }
-
- public void setPackageDeltas(Set<IPackageDelta> packageDeltas) {
- this.packageDeltas = packageDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigArrayTypeDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigArrayTypeDelta.java
deleted file mode 100644
index 5d47293..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigArrayTypeDelta.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IArrayTypeDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IArrayType;
-
-public class SigArrayTypeDelta extends SigTypeDelta<IArrayType> implements
- IArrayTypeDelta {
-
- private ITypeReferenceDelta<?> componentTypeDelta;
-
- public SigArrayTypeDelta(IArrayType from, IArrayType to) {
- super(from, to);
- }
-
- public ITypeReferenceDelta<?> getComponentTypeDelta() {
- return componentTypeDelta;
- }
-
- public void setComponentTypeDelta(
- ITypeReferenceDelta<?> componentTypeDelta) {
- this.componentTypeDelta = componentTypeDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigClassDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigClassDefinitionDelta.java
deleted file mode 100644
index 4034351..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigClassDefinitionDelta.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IAnnotationFieldDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IConstructorDelta;
-import signature.compare.model.IEnumConstantDelta;
-import signature.compare.model.IFieldDelta;
-import signature.compare.model.IMethodDelta;
-import signature.compare.model.IModifierDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.compare.model.ITypeVariableDefinitionDelta;
-import signature.model.IClassDefinition;
-
-import java.util.Set;
-
-public class SigClassDefinitionDelta extends
- SigTypeDefinitionDelta<IClassDefinition> implements
- IClassDefinitionDelta {
-
- public SigClassDefinitionDelta(IClassDefinition from, IClassDefinition to) {
- super(from, to);
- }
-
- private Set<IAnnotationFieldDelta> annotationFieldDeltas;
- private Set<IConstructorDelta> constructorDeltas;
- private Set<IEnumConstantDelta> enumConstantDeltas;
- private Set<IFieldDelta> fieldDeltas;
- private Set<ITypeReferenceDelta<?>> interfaceDeltas;
- private Set<IMethodDelta> methodDeltas;
- private Set<IModifierDelta> modifierDeltas;
- private ITypeReferenceDelta<?> superClassDelta;
- private Set<IAnnotationDelta> annotationDeltas;
- private Set<ITypeVariableDefinitionDelta> typeVariableDeltas;
-
- public Set<IAnnotationFieldDelta> getAnnotationFieldDeltas() {
- return annotationFieldDeltas;
- }
-
- public void setAnnotationFieldDeltas(
- Set<IAnnotationFieldDelta> annotationFieldDeltas) {
- this.annotationFieldDeltas = annotationFieldDeltas;
- }
-
- public Set<IConstructorDelta> getConstructorDeltas() {
- return constructorDeltas;
- }
-
- public void setConstructorDeltas(
- Set<IConstructorDelta> constructorDeltas) {
- this.constructorDeltas = constructorDeltas;
- }
-
- public Set<IEnumConstantDelta> getEnumConstantDeltas() {
- return enumConstantDeltas;
- }
-
- public void setEnumConstantDeltas(
- Set<IEnumConstantDelta> enumConstantDeltas) {
- this.enumConstantDeltas = enumConstantDeltas;
- }
-
- public Set<IFieldDelta> getFieldDeltas() {
- return fieldDeltas;
- }
-
- public void setFieldDeltas(Set<IFieldDelta> fieldDeltas) {
- this.fieldDeltas = fieldDeltas;
- }
-
- public Set<ITypeReferenceDelta<?>> getInterfaceDeltas() {
- return interfaceDeltas;
- }
-
- public void setInterfaceDeltas(
- Set<ITypeReferenceDelta<?>> interfaceDeltas) {
- this.interfaceDeltas = interfaceDeltas;
- }
-
- public Set<IMethodDelta> getMethodDeltas() {
- return methodDeltas;
- }
-
- public void setMethodDeltas(Set<IMethodDelta> methodDeltas) {
- this.methodDeltas = methodDeltas;
- }
-
- public Set<IModifierDelta> getModifierDeltas() {
- return modifierDeltas;
- }
-
- public void setModifierDeltas(Set<IModifierDelta> modifierDeltas) {
- this.modifierDeltas = modifierDeltas;
- }
-
- public ITypeReferenceDelta<?> getSuperClassDelta() {
- return superClassDelta;
- }
-
- public void setSuperClassDelta(ITypeReferenceDelta<?> superClassDelta) {
- this.superClassDelta = superClassDelta;
- }
-
- public Set<IAnnotationDelta> getAnnotationDeltas() {
- return annotationDeltas;
- }
-
- public void setAnnotationDeltas(Set<IAnnotationDelta> annotationDeltas) {
- this.annotationDeltas = annotationDeltas;
- }
-
- public Set<ITypeVariableDefinitionDelta> getTypeVariableDeltas() {
- return typeVariableDeltas;
- }
-
- public void setTypeVariableDeltas(
- Set<ITypeVariableDefinitionDelta> typeVariableDeltas) {
- this.typeVariableDeltas = typeVariableDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigClassReferenceDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigClassReferenceDelta.java
deleted file mode 100644
index 18741eb..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigClassReferenceDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IClassReference;
-
-public class SigClassReferenceDelta extends SigDelta<IClassReference>
- implements ITypeReferenceDelta<IClassReference> {
-
- public SigClassReferenceDelta(IClassReference from, IClassReference to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigConstructorDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigConstructorDelta.java
deleted file mode 100644
index 9a7cf70..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigConstructorDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IConstructorDelta;
-import signature.model.IConstructor;
-
-public class SigConstructorDelta extends SigExecutableMemberDelta<IConstructor>
- implements IConstructorDelta {
-
- public SigConstructorDelta(IConstructor from, IConstructor to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigDelta.java
deleted file mode 100644
index 933bf00..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigDelta.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import signature.compare.model.IDelta;
-import signature.compare.model.DeltaType;
-
-public abstract class SigDelta<T> implements IDelta<T> {
- private T from;
- private T to;
-
- public SigDelta(T from, T to) {
- this.from = from;
- this.to = to;
- }
-
- public final T getFrom() {
- return from;
- }
-
- public final T getTo() {
- return to;
- }
-
- public final DeltaType getType() {
- if (from == null && to != null) {
- return DeltaType.ADDED;
- }
- if (from != null && to == null) {
- return DeltaType.REMOVED;
- }
- return DeltaType.CHANGED;
- }
-
- private static <T extends IDelta<?>> Set<T> getDeltas(Set<T> deltas,
- DeltaType type) {
- Set<T> addedElements = new HashSet<T>();
- for (T delta : deltas) {
- if (type.equals(delta.getType())) {
- addedElements.add(delta);
- }
- }
- return addedElements;
- }
-
- public static <T extends IDelta<?>> Set<T> getAdded(Set<T> deltas) {
- return getDeltas(deltas, DeltaType.ADDED);
- }
-
- public static <T extends IDelta<?>> Set<T> getRemoved(Set<T> deltas) {
- return getDeltas(deltas, DeltaType.REMOVED);
- }
-
- public static <T extends IDelta<?>> Set<T> getChanged(Set<T> deltas) {
- return getDeltas(deltas, DeltaType.CHANGED);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(getClass().getSimpleName());
- builder.append(":\n");
-
- List<Field> allFields = new LinkedList<Field>();
-
- Class<?> actualClass = getClass();
-
- // add all fields / super classes also
- do {
- allFields.addAll(Arrays.asList(actualClass.getDeclaredFields()));
- actualClass = actualClass.getSuperclass();
- } while (actualClass != Object.class);
-
- builder.append("from: ");
- builder.append(from);
- builder.append("\nto: ");
- builder.append(to);
- builder.append("\n");
- try {
- for (Field field : allFields) {
- if (!ignore.contains(field.getName())) {
- field.setAccessible(true);
- Object delta = field.get(this);
- if (delta != null) {
- builder.append(field.getName());
- builder.append(":\n");
- builder.append(delta);
- }
- }
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- }
-
- return builder.toString();
- }
-
- private static Set<String> ignore = new HashSet<String>();
- {
- ignore.add("from");
- ignore.add("to");
- ignore.add("reason");
- ignore.add("ignore"); // =)
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigEnumConstantDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigEnumConstantDelta.java
deleted file mode 100644
index 3a7f9e7..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigEnumConstantDelta.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IEnumConstantDelta;
-import signature.compare.model.IValueDelta;
-import signature.model.IEnumConstant;
-
-public class SigEnumConstantDelta extends SigMemberDelta<IEnumConstant>
- implements IEnumConstantDelta {
-
- private IValueDelta ordinalDelta;
-
- public SigEnumConstantDelta(IEnumConstant from, IEnumConstant to) {
- super(from, to);
- }
-
- public IValueDelta getOrdinalDelta() {
- return ordinalDelta;
- }
-
- public void setOrdinalDelta(IValueDelta ordinalDelta) {
- this.ordinalDelta = ordinalDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigExecutableMemberDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigExecutableMemberDelta.java
deleted file mode 100644
index 1d871e4..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigExecutableMemberDelta.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IExecutableMemberDelta;
-import signature.compare.model.IModifierDelta;
-import signature.compare.model.IParameterDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.compare.model.ITypeVariableDefinitionDelta;
-import signature.model.IExecutableMember;
-
-import java.util.Set;
-
-public abstract class SigExecutableMemberDelta<T extends IExecutableMember>
- extends SigDelta<T> implements IExecutableMemberDelta<T> {
-
- private Set<ITypeReferenceDelta<?>> exceptionDeltas;
- private Set<IModifierDelta> modifierDeltas;
- private Set<ITypeVariableDefinitionDelta> typeVariableDeltas;
- private Set<IAnnotationDelta> annotationDeltas;
- private Set<IParameterDelta> parameterDeltas;
-
- public SigExecutableMemberDelta(T from, T to) {
- super(from, to);
- }
-
- public Set<ITypeReferenceDelta<?>> getExceptionDeltas() {
- return exceptionDeltas;
- }
-
- public void setExceptionDeltas(
- Set<ITypeReferenceDelta<?>> exceptionDeltas) {
- this.exceptionDeltas = exceptionDeltas;
- }
-
- public Set<IModifierDelta> getModifierDeltas() {
- return modifierDeltas;
- }
-
- public void setModifierDeltas(Set<IModifierDelta> modifierDeltas) {
- this.modifierDeltas = modifierDeltas;
- }
-
- public Set<ITypeVariableDefinitionDelta> getTypeVariableDeltas() {
- return typeVariableDeltas;
- }
-
- public void setTypeVariableDeltas(
- Set<ITypeVariableDefinitionDelta> typeVariableDeltas) {
- this.typeVariableDeltas = typeVariableDeltas;
- }
-
- public Set<IAnnotationDelta> getAnnotationDeltas() {
- return annotationDeltas;
- }
-
- public void setAnnotationDeltas(Set<IAnnotationDelta> annotationDeltas) {
- this.annotationDeltas = annotationDeltas;
- }
-
- public Set<IParameterDelta> getParameterDeltas() {
- return parameterDeltas;
- }
-
- public void setParameterDeltas(Set<IParameterDelta> parameterDeltas) {
- this.parameterDeltas = parameterDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigFieldDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigFieldDelta.java
deleted file mode 100644
index 6807eea..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigFieldDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IFieldDelta;
-import signature.model.IField;
-
-public class SigFieldDelta extends SigMemberDelta<IField> implements
- IFieldDelta {
-
- public SigFieldDelta(IField from, IField to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigGenericDeclarationDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigGenericDeclarationDelta.java
deleted file mode 100644
index d377b95..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigGenericDeclarationDelta.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IGenericDeclarationDelta;
-import signature.model.IGenericDeclaration;
-
-public class SigGenericDeclarationDelta extends SigDelta<IGenericDeclaration>
- implements IGenericDeclarationDelta {
-
- public SigGenericDeclarationDelta(IGenericDeclaration from,
- IGenericDeclaration to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigMemberDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigMemberDelta.java
deleted file mode 100644
index 2c5e9cb..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigMemberDelta.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.Set;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IMemberDelta;
-import signature.compare.model.IModifierDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IField;
-
-public abstract class SigMemberDelta<T extends IField> extends SigDelta<T>
- implements IMemberDelta<T> {
-
- private Set<IModifierDelta> modifierDeltas;
- private ITypeReferenceDelta<?> typeDelta;
- private Set<IAnnotationDelta> annotationDeltas;
-
-
- public SigMemberDelta(T from, T to) {
- super(from, to);
- }
-
- public Set<IModifierDelta> getModifierDeltas() {
- return modifierDeltas;
- }
-
- public void setModifierDeltas(Set<IModifierDelta> modifierDeltas) {
- this.modifierDeltas = modifierDeltas;
- }
-
- public ITypeReferenceDelta<?> getTypeDelta() {
- return typeDelta;
- }
-
- public void setTypeDelta(ITypeReferenceDelta<?> typeDelta) {
- this.typeDelta = typeDelta;
- }
-
- public Set<IAnnotationDelta> getAnnotationDeltas() {
- return annotationDeltas;
- }
-
- public void setAnnotationDeltas(Set<IAnnotationDelta> annotationDeltas) {
- this.annotationDeltas = annotationDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigMethodDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigMethodDelta.java
deleted file mode 100644
index 0a3fb2f..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigMethodDelta.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IMethodDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IMethod;
-
-public class SigMethodDelta extends SigExecutableMemberDelta<IMethod> implements
- IMethodDelta {
-
- private ITypeReferenceDelta<?> returnTypeDelta;
-
- public SigMethodDelta(IMethod from, IMethod to) {
- super(from, to);
- }
-
- public ITypeReferenceDelta<?> getReturnTypeDelta() {
- return returnTypeDelta;
- }
-
- public void setReturnTypeDelta(ITypeReferenceDelta<?> returnTypeDelta) {
- this.returnTypeDelta = returnTypeDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigModifierDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigModifierDelta.java
deleted file mode 100644
index aa5e380..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigModifierDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IModifierDelta;
-import signature.model.Modifier;
-
-public class SigModifierDelta extends SigDelta<Modifier> implements
- IModifierDelta {
-
- public SigModifierDelta(Modifier from, Modifier to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigPackageDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigPackageDelta.java
deleted file mode 100644
index 0f368f6..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigPackageDelta.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.Set;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IPackageDelta;
-import signature.model.IPackage;
-
-public class SigPackageDelta extends SigDelta<IPackage> implements
- IPackageDelta {
-
- private Set<IClassDefinitionDelta> classDeltas;
- private Set<IAnnotationDelta> annotationDeltas;
-
- public SigPackageDelta(IPackage from, IPackage to) {
- super(from, to);
- }
-
- public Set<IClassDefinitionDelta> getClassDeltas() {
- return classDeltas;
- }
-
- public void setClassDeltas(Set<IClassDefinitionDelta> classDeltas) {
- this.classDeltas = classDeltas;
- }
-
- public Set<IAnnotationDelta> getAnnotationDeltas() {
- return annotationDeltas;
- }
-
- public void setAnnotationDeltas(Set<IAnnotationDelta> annotationDeltas) {
- this.annotationDeltas = annotationDeltas;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigParameterDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigParameterDelta.java
deleted file mode 100644
index aee6466..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigParameterDelta.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.Set;
-
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IParameterDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IParameter;
-
-public class SigParameterDelta extends SigDelta<IParameter> implements
- IParameterDelta {
-
- private ITypeReferenceDelta<?> typeDelta;
- private Set<IAnnotationDelta> annotationDeltas;
-
- public SigParameterDelta(IParameter from, IParameter to) {
- super(from, to);
- }
-
- public ITypeReferenceDelta<?> getTypeDelta() {
- return typeDelta;
- }
-
- public void setTypeDelta(ITypeReferenceDelta<?> typeDelta) {
- this.typeDelta = typeDelta;
- }
-
- public Set<IAnnotationDelta> getAnnotationDeltas() {
- return annotationDeltas;
- }
-
- public void setAnnotationDeltas(Set<IAnnotationDelta> annotationDeltas) {
- this.annotationDeltas = annotationDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigParameterizedTypeDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigParameterizedTypeDelta.java
deleted file mode 100644
index 08fbc21..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigParameterizedTypeDelta.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.Set;
-
-import signature.compare.model.IParameterizedTypeDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.IParameterizedType;
-
-public class SigParameterizedTypeDelta extends SigTypeDelta<IParameterizedType>
- implements IParameterizedTypeDelta {
-
- private ITypeReferenceDelta<?> ownerTypeDelta;
- private ITypeReferenceDelta<?> rawTypeDelta;
- private Set<ITypeReferenceDelta<?>> argumentTypeDeltas;
-
- public SigParameterizedTypeDelta(IParameterizedType from,
- IParameterizedType to) {
- super(from, to);
- }
-
- public ITypeReferenceDelta<?> getOwnerTypeDelta() {
- return ownerTypeDelta;
- }
-
- public void setOwnerTypeDelta(ITypeReferenceDelta<?> ownerTypeDelta) {
- this.ownerTypeDelta = ownerTypeDelta;
- }
-
- public ITypeReferenceDelta<?> getRawTypeDelta() {
- return rawTypeDelta;
- }
-
- public void setRawTypeDelta(ITypeReferenceDelta<?> rawTypeDelta) {
- this.rawTypeDelta = rawTypeDelta;
- }
-
- public Set<ITypeReferenceDelta<?>> getArgumentTypeDeltas() {
- return argumentTypeDeltas;
- }
-
- public void setArgumentTypeDeltas(
- Set<ITypeReferenceDelta<?>> argumentTypeDeltas) {
- this.argumentTypeDeltas = argumentTypeDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigPrimitiveTypeDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigPrimitiveTypeDelta.java
deleted file mode 100644
index 03be8fa..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigPrimitiveTypeDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IPrimitiveTypeDelta;
-import signature.model.IPrimitiveType;
-
-public class SigPrimitiveTypeDelta extends SigTypeDelta<IPrimitiveType>
- implements IPrimitiveTypeDelta {
-
- public SigPrimitiveTypeDelta(IPrimitiveType from, IPrimitiveType to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigTypeDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigTypeDefinitionDelta.java
deleted file mode 100644
index c0bff8e..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigTypeDefinitionDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.ITypeDefinitionDelta;
-import signature.model.ITypeDefinition;
-
-public abstract class SigTypeDefinitionDelta<T extends ITypeDefinition> extends
- SigDelta<T> implements ITypeDefinitionDelta<T> {
-
- public SigTypeDefinitionDelta(T from, T to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigTypeDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigTypeDelta.java
deleted file mode 100644
index 718258c..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigTypeDelta.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.ITypeReference;
-
-public class SigTypeDelta<T extends ITypeReference> extends SigDelta<T>
- implements ITypeReferenceDelta<T> {
-
- public SigTypeDelta(T from, T to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableDefinitionDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableDefinitionDelta.java
deleted file mode 100644
index 348c728..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableDefinitionDelta.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IGenericDeclarationDelta;
-import signature.compare.model.ITypeVariableDefinitionDelta;
-import signature.compare.model.IUpperBoundsDelta;
-import signature.model.ITypeVariableDefinition;
-
-public class SigTypeVariableDefinitionDelta extends
- SigDelta<ITypeVariableDefinition> implements
- ITypeVariableDefinitionDelta {
-
- private IUpperBoundsDelta upperBoundsDelta;
- private IGenericDeclarationDelta genericDeclarationDelta;
-
- public SigTypeVariableDefinitionDelta(ITypeVariableDefinition from,
- ITypeVariableDefinition to) {
- super(from, to);
- }
-
- public IUpperBoundsDelta getUpperBoundsDelta() {
- return upperBoundsDelta;
- }
-
- public void setUpperBoundsDelta(IUpperBoundsDelta upperBoundsDelta) {
- this.upperBoundsDelta = upperBoundsDelta;
- }
-
- public IGenericDeclarationDelta getGenericDeclarationDelta() {
- return genericDeclarationDelta;
- }
-
- public void setGenericDeclarationDelta(
- IGenericDeclarationDelta genericDeclarationDelta) {
- this.genericDeclarationDelta = genericDeclarationDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableReferenceDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableReferenceDelta.java
deleted file mode 100644
index 4414a16..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigTypeVariableReferenceDelta.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IGenericDeclarationDelta;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.model.ITypeVariableReference;
-
-public class SigTypeVariableReferenceDelta extends
- SigDelta<ITypeVariableReference> implements
- ITypeReferenceDelta<ITypeVariableReference> {
-
- private IGenericDeclarationDelta genericDeclarationDelta;
-
- public SigTypeVariableReferenceDelta(ITypeVariableReference from,
- ITypeVariableReference to) {
- super(from, to);
- }
-
- public IGenericDeclarationDelta getGenericDeclarationDelta() {
- return genericDeclarationDelta;
- }
-
- public void setGenericDeclarationDelta(
- IGenericDeclarationDelta genericDeclarationDelta) {
- this.genericDeclarationDelta = genericDeclarationDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigUpperBoundsDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigUpperBoundsDelta.java
deleted file mode 100644
index 8822b26..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigUpperBoundsDelta.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import java.util.List;
-import java.util.Set;
-
-import signature.compare.model.ITypeReferenceDelta;
-import signature.compare.model.IUpperBoundsDelta;
-import signature.model.ITypeReference;
-
-public class SigUpperBoundsDelta extends SigDelta<List<ITypeReference>>
- implements IUpperBoundsDelta {
-
- private ITypeReferenceDelta<?> firstUpperBoundDelta;
- private Set<ITypeReferenceDelta<?>> remainingUpperBoundDeltas;
-
- public SigUpperBoundsDelta(List<ITypeReference> from,
- List<ITypeReference> to) {
- super(from, to);
- }
-
-
- public ITypeReferenceDelta<?> getFirstUpperBoundDelta() {
- return firstUpperBoundDelta;
- }
-
- public void setFirstUpperBoundDelta(
- ITypeReferenceDelta<?> firstUpperBoundDelta) {
- this.firstUpperBoundDelta = firstUpperBoundDelta;
- }
-
- public Set<ITypeReferenceDelta<?>> getRemainingUpperBoundDeltas() {
- return remainingUpperBoundDeltas;
- }
-
- public void setRemainingUpperBoundDeltas(
- Set<ITypeReferenceDelta<?>> remainingUpperBoundDeltas) {
- this.remainingUpperBoundDeltas = remainingUpperBoundDeltas;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigValueDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigValueDelta.java
deleted file mode 100644
index 9521f0e..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigValueDelta.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.IValueDelta;
-
-public class SigValueDelta extends SigDelta<Object> implements IValueDelta {
-
- public SigValueDelta(Object from, Object to) {
- super(from, to);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/impl/SigWildcardTypeDelta.java b/tools/signature-tools/src/signature/compare/model/impl/SigWildcardTypeDelta.java
deleted file mode 100644
index e6cafcb..0000000
--- a/tools/signature-tools/src/signature/compare/model/impl/SigWildcardTypeDelta.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.impl;
-
-import signature.compare.model.ITypeReferenceDelta;
-import signature.compare.model.IUpperBoundsDelta;
-import signature.compare.model.IWildcardTypeDelta;
-import signature.model.IWildcardType;
-
-public class SigWildcardTypeDelta extends SigTypeDelta<IWildcardType>
- implements IWildcardTypeDelta {
-
- private ITypeReferenceDelta<?> lowerBoundDelta;
- private IUpperBoundsDelta upperBoundDelta;
-
- public SigWildcardTypeDelta(IWildcardType from, IWildcardType to) {
- super(from, to);
- }
-
- public ITypeReferenceDelta<?> getLowerBoundDelta() {
- return lowerBoundDelta;
- }
-
- public void setLowerBoundDelta(ITypeReferenceDelta<?> lowerBoundDelta) {
- this.lowerBoundDelta = lowerBoundDelta;
- }
-
- public IUpperBoundsDelta getUpperBoundDelta() {
- return upperBoundDelta;
- }
-
- public void setUpperBoundDelta(IUpperBoundsDelta upperBoundDelta) {
- this.upperBoundDelta = upperBoundDelta;
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ArrayTypeProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ArrayTypeProjection.java
deleted file mode 100644
index 428146e..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ArrayTypeProjection.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import java.util.Map;
-
-import signature.model.IArrayType;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.impl.SigArrayType;
-
-public class ArrayTypeProjection implements IArrayType {
-
- private final IArrayType original;
- private final Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public ArrayTypeProjection(IArrayType original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public ITypeReference getComponentType() {
- return ViewpointAdapter.substitutedTypeReference(original
- .getComponentType(), mappings);
- }
-
- @Override
- public int hashCode() {
- return SigArrayType.hashCode(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigArrayType.equals(this, obj);
- }
-
- @Override
- public String toString() {
- return "(" + SigArrayType.toString(this) + " : " + mappings + " )";
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ClassProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ClassProjection.java
deleted file mode 100644
index 630d102..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ClassProjection.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import signature.model.IAnnotation;
-import signature.model.IAnnotationField;
-import signature.model.IClassDefinition;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IField;
-import signature.model.IMethod;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigClassDefinition;
-
-public class ClassProjection implements IClassDefinition {
-
- private final IClassDefinition original;
- private final Map<ITypeVariableDefinition, ITypeReference> substitutions;
-
- public ClassProjection(IClassDefinition original,
- Map<ITypeVariableDefinition, ITypeReference> mapping) {
- this.original = original;
- this.substitutions = mapping;
- }
-
- public Set<IAnnotationField> getAnnotationFields() {
- throw new UnsupportedOperationException();
- }
-
- public Set<IAnnotation> getAnnotations() {
- throw new UnsupportedOperationException();
- }
-
- public Set<IConstructor> getConstructors() {
- throw new UnsupportedOperationException();
- }
-
- public IClassDefinition getDeclaringClass() {
- throw new UnsupportedOperationException();
- }
-
- public Set<IEnumConstant> getEnumConstants() {
- throw new UnsupportedOperationException();
- }
-
- public Set<IField> getFields() {
- throw new UnsupportedOperationException();
- }
-
- public Set<IClassDefinition> getInnerClasses() {
- throw new UnsupportedOperationException();
- }
-
- Set<ITypeReference> interfaces = null;
-
- public Set<ITypeReference> getInterfaces() {
- if (interfaces == null) {
- Set<ITypeReference> originalInterfaces = original.getInterfaces();
- if (originalInterfaces == null) {
- interfaces = Collections.emptySet();
- } else {
- interfaces = new HashSet<ITypeReference>();
- for (ITypeReference interfaze : originalInterfaces) {
- interfaces.add(ViewpointAdapter.substitutedTypeReference(
- interfaze, substitutions));
- }
- interfaces = Collections.unmodifiableSet(interfaces);
- }
- }
- return interfaces;
- }
-
- public Kind getKind() {
- return original.getKind();
- }
-
-
- Set<IMethod> methods = null;
-
- public Set<IMethod> getMethods() {
- if (methods == null) {
- Set<IMethod> originalMethods = original.getMethods();
- if (originalMethods == null) {
- methods = Collections.emptySet();
- } else {
- methods = new HashSet<IMethod>();
- for (IMethod m : original.getMethods()) {
- methods.add(new MethodProjection(m, substitutions));
- }
- methods = Collections.unmodifiableSet(methods);
- }
- }
- return methods;
- }
-
- public Set<Modifier> getModifiers() {
- return original.getModifiers();
- }
-
- public String getName() {
- return original.getName();
- }
-
- public List<String> getPackageFragments() {
- return original.getPackageFragments();
- }
-
- public String getPackageName() {
- return original.getPackageName();
- }
-
- public String getQualifiedName() {
- return original.getQualifiedName();
- }
-
- private boolean superClassInit = false;
- private ITypeReference superClass = null;
-
- public ITypeReference getSuperClass() {
- if (!superClassInit) {
- ITypeReference originalSuperClass = original.getSuperClass();
- if (originalSuperClass != null) {
- superClass = ViewpointAdapter.substitutedTypeReference(original
- .getSuperClass(), substitutions);
- }
- superClassInit = true;
- }
- return superClass;
- }
-
- // Definitions of type variables are not substituted
- public List<ITypeVariableDefinition> getTypeParameters() {
- return original.getTypeParameters();
- }
-
- @Override
- public int hashCode() {
- return SigClassDefinition.hashCode(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigClassDefinition.equals(this, obj);
- }
-
- @Override
- public String toString() {
- return "(" + SigClassDefinition.toString(this) + " : " + substitutions
- + " )";
- }
-
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ClassReferenceProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ClassReferenceProjection.java
deleted file mode 100644
index 648ccf8..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ClassReferenceProjection.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.impl.SigClassReference;
-
-import java.util.Map;
-
-public class ClassReferenceProjection implements IClassReference {
-
- private final IClassReference original;
- private final Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public ClassReferenceProjection(IClassReference original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public IClassDefinition getClassDefinition() {
- return new ClassProjection(original.getClassDefinition(), mappings);
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigClassReference.equals(this, obj);
- }
-
- @Override
- public int hashCode() {
- return SigClassReference.hashCode(this);
- }
-
- @Override
- public String toString() {
- return "(" + SigClassReference.toString(this) + " : " + mappings + " )";
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ConstructorProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ConstructorProjection.java
deleted file mode 100644
index 1ffd616..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ConstructorProjection.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IConstructor;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-
-import java.util.Map;
-
-public class ConstructorProjection extends ExecutableMemberProjection implements
- IConstructor {
-
- public ConstructorProjection(IConstructor original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- super(original, mappings);
- }
-
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ExecutableMemberProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ExecutableMemberProjection.java
deleted file mode 100644
index f96ac54..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ExecutableMemberProjection.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IAnnotation;
-import signature.model.IClassDefinition;
-import signature.model.IExecutableMember;
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.Modifier;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public abstract class ExecutableMemberProjection implements IExecutableMember {
-
- private final IExecutableMember original;
- private final Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public ExecutableMemberProjection(IExecutableMember original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public Set<IAnnotation> getAnnotations() {
- return original.getAnnotations();
- }
-
- public IClassDefinition getDeclaringClass() {
- throw new UnsupportedOperationException();
- }
-
- public Set<ITypeReference> getExceptions() {
- return ViewpointAdapter.substitutedTypeReferences(original
- .getExceptions(), mappings);
- }
-
- public Set<Modifier> getModifiers() {
- return original.getModifiers();
- }
-
- public String getName() {
- return original.getName();
- }
-
- public List<IParameter> getParameters() {
- List<IParameter> result = new LinkedList<IParameter>();
- for (IParameter parameter : original.getParameters()) {
- result.add(new ParameterProjection(parameter, mappings));
- }
- return result;
- }
-
- public List<ITypeVariableDefinition> getTypeParameters() {
- // FIXME bounds need to be substituted ?
- return original.getTypeParameters();
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/MethodProjection.java b/tools/signature-tools/src/signature/compare/model/subst/MethodProjection.java
deleted file mode 100644
index c98fb09..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/MethodProjection.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IMethod;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.impl.SigMethod;
-
-import java.util.Map;
-
-public class MethodProjection extends ExecutableMemberProjection implements
- IMethod {
-
- private final IMethod original;
- private Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public MethodProjection(IMethod original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- super(original, mappings);
- this.mappings = mappings;
- this.original = original;
- }
-
- public ITypeReference getReturnType() {
- return ViewpointAdapter.substitutedTypeReference(original
- .getReturnType(), mappings);
- }
-
- @Override
- public String toString() {
- return "(" + SigMethod.toString(this) + " : " + mappings + " )";
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ParameterProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ParameterProjection.java
deleted file mode 100644
index 9c48ab7..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ParameterProjection.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IAnnotation;
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-
-import java.util.Map;
-import java.util.Set;
-
-public class ParameterProjection implements IParameter {
- private IParameter original;
- private Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public ParameterProjection(IParameter original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public Set<IAnnotation> getAnnotations() {
- return original.getAnnotations();
- }
-
- public ITypeReference getType() {
- return ViewpointAdapter.substitutedTypeReference(original.getType(),
- mappings);
- }
-
- @Override
- public String toString() {
- return getType().toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ParameterizedTypeProjection.java b/tools/signature-tools/src/signature/compare/model/subst/ParameterizedTypeProjection.java
deleted file mode 100644
index 59836db..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ParameterizedTypeProjection.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IClassReference;
-import signature.model.IParameterizedType;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.impl.SigParameterizedType;
-
-import java.util.List;
-import java.util.Map;
-
-public class ParameterizedTypeProjection implements IParameterizedType {
-
- private final IParameterizedType original;
-
- private final Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public ParameterizedTypeProjection(IParameterizedType original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public ITypeReference getOwnerType() {
- ITypeReference ownerType = original.getOwnerType();
- if (ownerType == null) {
- return null;
- }
- return ViewpointAdapter.substitutedTypeReference(ownerType, mappings);
- }
-
- private IClassReference rawType = null;
-
- /**
- * Returns the raw type with substituted type variables.
- *
- * @return the raw type with substituted type variables
- */
- public IClassReference getRawType() {
- if (rawType == null) {
- rawType = (IClassReference) ViewpointAdapter
- .substitutedTypeReference(original.getRawType(),
- ViewpointAdapter.createTypeMapping(this, original
- .getRawType().getClassDefinition()));
- }
- return rawType;
- }
-
- private List<ITypeReference> arguments = null;
-
- public List<ITypeReference> getTypeArguments() {
- if (arguments == null) {
- arguments = ViewpointAdapter.substitutedTypeReferences(original
- .getTypeArguments(), mappings);
- }
- return arguments;
- }
-
- @Override
- public int hashCode() {
- return SigParameterizedType.hashCode(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigParameterizedType.equals(this, obj);
- }
-
- @Override
- public String toString() {
- return SigParameterizedType.toString(this);
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/ViewpointAdapter.java b/tools/signature-tools/src/signature/compare/model/subst/ViewpointAdapter.java
deleted file mode 100644
index 88f457f..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/ViewpointAdapter.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IParameterizedType;
-import signature.model.IPrimitiveType;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.IWildcardType;
-import signature.model.impl.SigClassReference;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class ViewpointAdapter {
-
- static Map<ITypeVariableDefinition, ITypeReference> createTypeMapping(
- IParameterizedType paramameterizedType,
- IClassDefinition parameterizedTypeDefinition) {
- List<ITypeVariableDefinition> typeParameters =
- parameterizedTypeDefinition.getTypeParameters();
- List<ITypeReference> actualTypeArguments = paramameterizedType
- .getTypeArguments();
- if (actualTypeArguments == null || typeParameters == null) {
- return Collections.emptyMap();
- }
- Map<ITypeVariableDefinition, ITypeReference> substitution =
- new HashMap<ITypeVariableDefinition, ITypeReference>();
- Iterator<ITypeVariableDefinition> paramsIterator = typeParameters
- .iterator();
- Iterator<ITypeReference> argumentsIterator = actualTypeArguments
- .iterator();
- while (paramsIterator.hasNext() && argumentsIterator.hasNext()) {
- substitution.put(paramsIterator.next(), argumentsIterator.next());
- }
- return substitution;
- }
-
- public static Set<ITypeReference> substitutedTypeReferences(
- Set<ITypeReference> original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- List<ITypeReference> result = new ArrayList<ITypeReference>(original);
- return new HashSet<ITypeReference>(substitutedTypeReferences(result,
- mappings));
- }
-
- public static List<ITypeReference> substitutedTypeReferences(
- List<ITypeReference> original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- List<ITypeReference> result = new ArrayList<ITypeReference>(original
- .size());
- for (ITypeReference typeReference : original) {
- result.add(substitutedTypeReference(typeReference, mappings));
- }
- return result;
- }
-
- public static ITypeReference substitutedTypeReference(
- ITypeReference original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- ITypeReference type = original;
- if (type instanceof IClassReference) {
- return new ClassReferenceProjection((IClassReference) original,
- mappings);
- } else if (type instanceof IPrimitiveType) {
- return type;
- } else if (type instanceof IArrayType) {
- return new ArrayTypeProjection((IArrayType) type, mappings);
- } else if (type instanceof IParameterizedType) {
- return new ParameterizedTypeProjection((IParameterizedType) type,
- mappings);
- } else if (type instanceof IWildcardType) {
- return new WildcardTypeProjection((IWildcardType) type, mappings);
- } else if (type instanceof ITypeVariableReference) {
- // here happens the substitution
- ITypeReference subst = mappings.get(((ITypeVariableReference) type)
- .getTypeVariableDefinition());
- return subst != null ? subst : type;
- }
- throw new IllegalStateException();
- }
-
- public static IClassReference getReferenceTo(IClassDefinition definition) {
- return new SigClassReference(new ClassProjection(definition,
- new HashMap<ITypeVariableDefinition, ITypeReference>()));
- }
-}
diff --git a/tools/signature-tools/src/signature/compare/model/subst/WildcardTypeProjection.java b/tools/signature-tools/src/signature/compare/model/subst/WildcardTypeProjection.java
deleted file mode 100644
index a59873c..0000000
--- a/tools/signature-tools/src/signature/compare/model/subst/WildcardTypeProjection.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.compare.model.subst;
-
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.IWildcardType;
-import signature.model.impl.SigWildcardType;
-
-import java.util.List;
-import java.util.Map;
-
-public class WildcardTypeProjection implements IWildcardType {
-
- private final IWildcardType original;
-
- private final Map<ITypeVariableDefinition, ITypeReference> mappings;
-
- public WildcardTypeProjection(IWildcardType original,
- Map<ITypeVariableDefinition, ITypeReference> mappings) {
- this.original = original;
- this.mappings = mappings;
- }
-
- public ITypeReference getLowerBound() {
- return ViewpointAdapter.substitutedTypeReference(original
- .getLowerBound(), mappings);
- }
-
- public List<ITypeReference> getUpperBounds() {
- return ViewpointAdapter.substitutedTypeReferences(original
- .getUpperBounds(), mappings);
- }
-
- @Override
- public int hashCode() {
- return SigWildcardType.hashCode(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigWildcardType.equals(this, obj);
- }
-
- @Override
- public String toString() {
- return SigWildcardType.toString(this);
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/Main.java b/tools/signature-tools/src/signature/converter/Main.java
deleted file mode 100644
index f426877..0000000
--- a/tools/signature-tools/src/signature/converter/Main.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import signature.UsageException;
-import signature.converter.dex.DexFactory;
-import signature.converter.doclet.DocletFactory;
-import signature.io.IApiLoader;
-import signature.io.IApiExternalizer;
-import signature.io.impl.BinaryApi;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-
-public class Main {
- // (doclet | dex) sourcefiles --out file --name name --packages packageName{
- // packageName}" +
- public static void main(String[] args) throws IOException {
- String type = args[0];
- Set<String> sources = new HashSet<String>();
- int at = 1;
- for (/* at */; at < args.length; at++) {
- if ("--out".equals(args[at])) {
- break;
- }
- sources.add(args[at]);
- }
-
- if (!"--out".equals(args[at])) {
- throw new UsageException();
- }
- String targetFile = args[++at];
-
- if (!"--name".equals(args[++at])) {
- throw new UsageException();
- }
- String name = args[++at];
-
- if (!"--packages".equals(args[++at])) {
- throw new UsageException();
- }
- Set<String> packages = new HashSet<String>();
- ++at;
- for (/* at */; at < args.length; at++) {
- packages.add(args[at]);
- }
-
- IApiExternalizer externalizer = new BinaryApi();
- IApiLoader factory = null;
-
- if ("doclet".equals(type)) {
- factory = new DocletFactory();
- } else if ("dex".equals(type)) {
- factory = new DexFactory();
- } else {
- throw new UsageException();
- }
-
- externalizer.externalizeApi(targetFile, factory.loadApi(name,
- Visibility.PROTECTED, sources, packages));
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/Visibility.java b/tools/signature-tools/src/signature/converter/Visibility.java
deleted file mode 100644
index 653c617..0000000
--- a/tools/signature-tools/src/signature/converter/Visibility.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-/**
- * This enum defines which members are part of the API.
- *
- * <ul>
- * <li><code>PUBLIC</code> only the public classes and members are included.
- * <li><code>PROTECTED</code> the public and protected classes members are
- * included.
- * <li><code>PACKAGE</code> the public, protected and package visible classes
- * and members are included.
- * <li><code>PRIVATE</code> all classes and members are included.
- * </ul>
- * <p>
- * The default visibility mode is <code>PROTECTED</code>.
- *
- */
-public enum Visibility {
- PUBLIC, PROTECTED, PACKAGE, PRIVATE;
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/DexFactory.java b/tools/signature-tools/src/signature/converter/dex/DexFactory.java
deleted file mode 100644
index b7cc00e..0000000
--- a/tools/signature-tools/src/signature/converter/dex/DexFactory.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import dex.structure.DexFile;
-import signature.converter.Visibility;
-import signature.io.IApiLoader;
-import signature.model.IApi;
-import signature.model.IPackage;
-import signature.model.impl.SigApi;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-
-public class DexFactory implements IApiLoader {
-
- public IApi loadApi(String name, Visibility visibility,
- Set<String> fileNames, Set<String> packageNames) throws
- IOException {
- DexToSigConverter converter = new DexToSigConverter();
- Set<DexFile> files = DexUtil.getDexFiles(fileNames);
- SigApi api = converter.convertApi(name, files, visibility);
-
- Iterator<IPackage> it = api.getPackages().iterator();
- while (it.hasNext()) {
- IPackage aPackage = it.next();
- boolean found = false;
- for (String packageName : packageNames) {
- if (aPackage.getName().equals(packageName)) {
- found = true;
- }
- }
- if (!found) {
- it.remove();
- }
- }
- return api;
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/DexToSigConverter.java b/tools/signature-tools/src/signature/converter/dex/DexToSigConverter.java
deleted file mode 100644
index 13312bd..0000000
--- a/tools/signature-tools/src/signature/converter/dex/DexToSigConverter.java
+++ /dev/null
@@ -1,938 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import static signature.converter.dex.DexUtil.convertAnyWay;
-import static signature.converter.dex.DexUtil.declaresExceptions;
-import static signature.converter.dex.DexUtil.declaresMemberClasses;
-import static signature.converter.dex.DexUtil.findPackageInfo;
-import static signature.converter.dex.DexUtil.getClassModifiers;
-import static signature.converter.dex.DexUtil.getClassName;
-import static signature.converter.dex.DexUtil.getDefaultMappingsAnnotation;
-import static signature.converter.dex.DexUtil.getDexName;
-import static signature.converter.dex.DexUtil.getEnclosingClassName;
-import static signature.converter.dex.DexUtil.getExceptionSignature;
-import static signature.converter.dex.DexUtil.getGenericSignature;
-import static signature.converter.dex.DexUtil.getKind;
-import static signature.converter.dex.DexUtil.getMemberClassNames;
-import static signature.converter.dex.DexUtil.getModifier;
-import static signature.converter.dex.DexUtil.getPackageName;
-import static signature.converter.dex.DexUtil.getQualifiedName;
-import static signature.converter.dex.DexUtil.hasAnnotationDefaultSignature;
-import static signature.converter.dex.DexUtil.hasGenericSignature;
-import static signature.converter.dex.DexUtil.isAnnotation;
-import static signature.converter.dex.DexUtil.isConstructor;
-import static signature.converter.dex.DexUtil.isEnclosingClass;
-import static signature.converter.dex.DexUtil.isEnum;
-import static signature.converter.dex.DexUtil.isInternalAnnotation;
-import static signature.converter.dex.DexUtil.isJavaLangObject;
-import static signature.converter.dex.DexUtil.isMethod;
-import static signature.converter.dex.DexUtil.isVisible;
-import static signature.converter.dex.DexUtil.splitTypeList;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IAnnotation;
-import signature.model.IAnnotationElement;
-import signature.model.IAnnotationField;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IField;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigAnnotation;
-import signature.model.impl.SigAnnotationElement;
-import signature.model.impl.SigAnnotationField;
-import signature.model.impl.SigApi;
-import signature.model.impl.SigClassDefinition;
-import signature.model.impl.SigClassReference;
-import signature.model.impl.SigConstructor;
-import signature.model.impl.SigEnumConstant;
-import signature.model.impl.SigExecutableMember;
-import signature.model.impl.SigField;
-import signature.model.impl.SigMethod;
-import signature.model.impl.SigPackage;
-import signature.model.impl.SigParameter;
-import signature.model.impl.Uninitialized;
-import signature.model.util.TypePool;
-import dex.structure.DexAnnotation;
-import dex.structure.DexAnnotationAttribute;
-import dex.structure.DexClass;
-import dex.structure.DexEncodedAnnotation;
-import dex.structure.DexEncodedValue;
-import dex.structure.DexField;
-import dex.structure.DexFile;
-import dex.structure.DexMethod;
-import dex.structure.DexParameter;
-
-/**
- * Converts a set of dex files to the signature compare api.
- */
-public final class DexToSigConverter implements IClassInitializer {
-
- private final FieldPool elementPool;
- private final TypePool factory;
- private static final Set<IField> EMPTY_FIELDS = Collections.emptySet();
- private static final Set<IEnumConstant> EMPTY_ENUM_CONSTANTS = Collections
- .emptySet();
- private static final Set<IAnnotationField> EMPTY_ANNOTATION_FIELDS =
- Collections.emptySet();
- private static final List<ITypeVariableDefinition> EMPTY_TYPE_VARIABLES =
- Collections.emptyList();
- private static final Set<IClassDefinition> EMPTY_INNER_CLASSES =
- Collections.emptySet();
- private static final Set<ITypeReference> EMPTY_EXCEPTIONS = Collections
- .emptySet();
- private Visibility visibility;
- private Map<String, DexClass> dexNameToDexClass;
-
-
- /**
- * Creates a new instance of {@link DexToSigConverter}.
- */
- public DexToSigConverter() {
- factory = new TypePool();
- elementPool = new FieldPool();
- }
-
-
- public SigApi convertApi(String apiName, Set<DexFile> dexFiles,
- Visibility visibility) {
- this.visibility = visibility;
- SigApi api = new SigApi(apiName, visibility);
- api.setPackages(convertPackages(dexFiles));
- factory.replaceAllUninitialiezWithNull();
- return api;
- }
-
- /**
- * Converts the given {@link DexFile}s into the corresponding (packages
- * including their (classes and their members, etc.))E
- *
- * @param parsedFiles
- * the dex files to convert
- * @return the converted packages
- */
- /* package */Set<IPackage> convertPackages(Set<DexFile> parsedFiles) {
- Map<String, SigPackage> packageNameToPackage =
- new HashMap<String, SigPackage>();
- Map<SigPackage, Set<DexClass>> packageToDexClasses =
- new HashMap<SigPackage, Set<DexClass>>();
-
- dexNameToDexClass = new HashMap<String, DexClass>();
-
- for (DexFile dexFile : parsedFiles) {
- List<DexClass> definedClasses = dexFile.getDefinedClasses();
- for (DexClass dexClass : definedClasses) {
-
- dexNameToDexClass.put(dexClass.getName(), dexClass);
-
- String dexName = dexClass.getName();
- String packageName = getPackageName(dexName);
- SigPackage aPackage = packageNameToPackage.get(packageName);
- if (aPackage == null) {
- aPackage = convertPackage(packageName);
- packageNameToPackage.put(packageName, aPackage);
-
- Set<DexClass> classes = new HashSet<DexClass>();
- packageToDexClasses.put(aPackage, classes);
- }
- Set<DexClass> classes = packageToDexClasses.get(aPackage);
- classes.add(dexClass);
- }
- }
-
- Set<SigClassDefinition> allClasses = new HashSet<SigClassDefinition>();
-
- for (SigPackage aPackage : packageToDexClasses.keySet()) {
- Set<SigClassDefinition> classes = convertClasses(packageToDexClasses
- .get(aPackage));
- allClasses.addAll(classes);
- aPackage.setClasses(new HashSet<IClassDefinition>(classes));
- }
-
- // remove package info
- for (SigPackage aPackage : packageToDexClasses.keySet()) {
- IClassDefinition packageInfo = findPackageInfo(aPackage);
- if (packageInfo != null) {
- aPackage.setAnnotations(packageInfo.getAnnotations());
- aPackage.getClasses().remove(packageInfo);
- }
- }
-
- // link enclosed classes only if they are part of visible api
- for (SigClassDefinition sigClass : allClasses) {
- String dexName = getDexName(sigClass);
- DexClass dexClass = dexNameToDexClass.get(dexName);
-
- if (declaresMemberClasses(dexClass)) {
- Set<String> enclosedClassesNames =
- getMemberClassNames(dexClass);
- Set<IClassDefinition> memberClasses =
- new HashSet<IClassDefinition>();
- for (String enclosedClassName : enclosedClassesNames) {
- SigClassDefinition memberClass = factory.getClass(
- getPackageName(enclosedClassName),
- getClassName(enclosedClassName));
- // add inner class only if parsed
- if (allClasses.contains(memberClass)) {
- memberClasses.add(memberClass);
- }
- }
- sigClass.setInnerClasses(memberClasses);
- } else {
- sigClass.setInnerClasses(EMPTY_INNER_CLASSES);
- }
- }
-
- // remove inner classes, is outer class is not visible
- for (SigClassDefinition sigClass : allClasses) {
- if (hasInvisibleParent(sigClass, dexNameToDexClass)) {
- SigPackage sigPackage = packageNameToPackage.get(sigClass
- .getPackageName());
- sigPackage.getClasses().remove(sigClass);
- }
- }
- return new HashSet<IPackage>(packageToDexClasses.keySet());
- }
-
- private boolean hasInvisibleParent(IClassDefinition sigClass,
- Map<String, DexClass> dexNameToDexClass) {
-
- do {
- String dexName = getDexName(sigClass);
- DexClass dexClass = dexNameToDexClass.get(dexName);
- if (isEnclosingClass(dexClass)) {
- IClassDefinition declaringClass = sigClass.getDeclaringClass();
- DexClass declaringDexClass = dexNameToDexClass
- .get(getDexName(declaringClass));
- if (!isVisible(declaringDexClass, visibility)) {
- return true;
- }
- }
- } while ((sigClass = sigClass.getDeclaringClass()) != null);
- return false;
- }
-
- /**
- * Converts a simple string to the corresponding {@link SigPackage}.<br>
- * Format: "a.b.c"
- *
- * @param packageName
- * the name of the package
- * @return the package
- */
- protected SigPackage convertPackage(String packageName) {
- SigPackage sigPackage = new SigPackage(packageName);
- return sigPackage;
- }
-
- /**
- * Converts a set of {@link DexClass} objects to a set of the corresponding
- * {@link SigClassDefinition} objects.
- *
- * @param dexClasses
- * the {@link DexClass} objects
- * @return a set of {@link DexClass} objects
- */
- protected Set<SigClassDefinition> convertClasses(Set<DexClass> dexClasses) {
- Set<SigClassDefinition> classes = new HashSet<SigClassDefinition>();
- for (DexClass dexClass : dexClasses) {
- // convert all classes but synthetic, return only initialized
- if (convertAnyWay(dexClass)) {
- SigClassDefinition sigCLass = convertClass(dexClass);
- if (isVisible(dexClass, visibility)) {
- classes.add(sigCLass);
- }
- }
- }
- return classes;
- }
-
- /**
- * Converts a {@link DexClass} to the corresponding
- * {@link SigClassDefinition}.
- *
- * @param dexClass
- * the {@link DexClass} to convert
- * @return the corresponding {@link SigClassDefinition}
- */
- protected SigClassDefinition convertClass(DexClass dexClass) {
- assert dexClass != null;
-
- String packageName = getPackageName(dexClass.getName());
- String className = getClassName(dexClass.getName());
- SigClassDefinition sigClass = factory.getClass(packageName, className);
- // Kind
- sigClass.setKind(getKind(dexClass));
- // modifiers
- Set<Modifier> modifiers = getModifier(getClassModifiers(dexClass));
- sigClass.setModifiers(modifiers);
-
- if (isEnclosingClass(dexClass)) {
- String declaringClassDexName = getEnclosingClassName(dexClass);
- declaringClassDexName = getClassName(declaringClassDexName);
- // declaring class is in same package
- sigClass.setDeclaringClass(factory.getClass(sigClass
- .getPackageName(), declaringClassDexName));
- } else {
- sigClass.setDeclaringClass(null);
- }
-
- if (hasGenericSignature(dexClass)) {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- parser.parseForClass(sigClass, getGenericSignature(dexClass));
- sigClass.setTypeParameters(parser.formalTypeParameters);
-
- if (Kind.INTERFACE.equals(sigClass.getKind())) {
- sigClass.setSuperClass(null);
- } else {
- sigClass.setSuperClass(parser.superclassType);
- }
-
- sigClass.setInterfaces(new HashSet<ITypeReference>(
- parser.interfaceTypes));
- } else {
-
- // Type parameters
- sigClass.setTypeParameters(EMPTY_TYPE_VARIABLES);
-
- // java.lang.Object has no super class
- if (isJavaLangObject(dexClass)) {
- sigClass.setSuperClass(null);
- } else {
-
- if (Kind.INTERFACE.equals(sigClass.getKind())
- || Kind.ANNOTATION.equals(sigClass.getKind())) {
- sigClass.setSuperClass(null);
- } else {
- String superClassPackageName = getPackageName(dexClass
- .getSuperClass());
- String superClassName = getClassName(dexClass
- .getSuperClass());
- sigClass.setSuperClass(factory.getClassReference(
- superClassPackageName, superClassName));
- }
- }
-
- List<String> interfaceDexNames = dexClass.getInterfaces();
- Set<ITypeReference> interfaces = new HashSet<ITypeReference>();
- for (String interfaceDexName : interfaceDexNames) {
- String interfacePackageName = getPackageName(interfaceDexName);
- String interfaceName = getClassName(interfaceDexName);
- SigClassDefinition interfaze = factory.getClass(
- interfacePackageName, interfaceName);
- interfaze.setKind(Kind.INTERFACE);
- interfaces.add(new SigClassReference(interfaze));
- }
- sigClass.setInterfaces(interfaces);
- }
-
- // constructors
- Set<SigConstructor> constructors = convertConstructors(dexClass
- .getMethods());
- for (SigConstructor constructor : constructors) {
- constructor.setDeclaringClass(sigClass);
- }
- sigClass.setConstructors(new HashSet<IConstructor>(constructors));
-
- // methods
- Set<SigMethod> methods = Collections.emptySet();
-
-
- if (isAnnotation(dexClass)) {
- Map<String, Object> mappings = getDefaultValueMapping(dexClass);
- Set<SigAnnotationField> annotationFields = convertAnnotationFields(
- dexClass.getMethods(), mappings);
- sigClass.setAnnotationFields(new HashSet<IAnnotationField>(
- annotationFields));
- addAnnotationsToAnnotationFields(dexClass.getMethods(),
- annotationFields);
-
- sigClass.setEnumConstants(EMPTY_ENUM_CONSTANTS);
- sigClass.setFields(EMPTY_FIELDS);
-
- // sigClass.setAnnotationFields(new
- // HashSet<IAnnotationField>(convertAnnotationFields(dexClass)));
- } else if (isEnum(dexClass)) {
- Set<IField> fields = new HashSet<IField>();
- Set<IEnumConstant> enumConstants = new HashSet<IEnumConstant>();
-
- for (DexField dexField : dexClass.getFields()) {
- if (isVisible(dexField, visibility)) {
- if (dexField.isEnumConstant()) {
- enumConstants.add(convertEnumConstant(dexField));
- } else {
- fields.add(convertField(dexField));
- }
- }
- }
-
- sigClass.setFields(fields);
- sigClass.setEnumConstants(enumConstants);
- sigClass.setAnnotationFields(EMPTY_ANNOTATION_FIELDS);
- methods = convertMethods(dexClass.getMethods());
- } else {
- // fields
- sigClass.setFields(new HashSet<IField>(convertFields(dexClass
- .getFields())));
- sigClass.setEnumConstants(EMPTY_ENUM_CONSTANTS);
- sigClass.setAnnotationFields(EMPTY_ANNOTATION_FIELDS);
- methods = convertMethods(dexClass.getMethods());
- }
-
- for (SigMethod method : methods) {
- method.setDeclaringClass(sigClass);
- }
- sigClass.setMethods(new HashSet<IMethod>(methods));
-
- // Annotations
- sigClass.setAnnotations(convertAnnotations(dexClass.getAnnotations()));
-
- return sigClass;
- }
-
- @SuppressWarnings("unchecked")
- private Map<String, Object> getDefaultValueMapping(DexClass dexClass) {
- HashMap<String, Object> mappings = new HashMap<String, Object>();
- if (hasAnnotationDefaultSignature(dexClass)) {
- // read mapping to defaults from annotation
- DexAnnotation annotation = getDefaultMappingsAnnotation(dexClass);
- DexAnnotationAttribute dexAnnotationAttribute = annotation
- .getAttributes().get(0);
- if ("value".equals(dexAnnotationAttribute.getName())) {
- DexEncodedValue encodedValue = dexAnnotationAttribute
- .getEncodedValue();
- DexEncodedValue value = (DexEncodedValue) encodedValue
- .getValue();
- List<DexAnnotationAttribute> defaults =
- (List<DexAnnotationAttribute>) value.getValue();
- for (DexAnnotationAttribute defaultAttribute : defaults) {
- mappings.put(defaultAttribute.getName(),
- convertEncodedValue(defaultAttribute
- .getEncodedValue()));
- }
- }
- }
- return mappings;
- }
-
-
- private void addAnnotationsToAnnotationFields(List<DexMethod> methods,
- Set<SigAnnotationField> annotationFields) {
- Map<String, SigAnnotationField> nameToAnnotationField =
- new HashMap<String, SigAnnotationField>();
-
- for (SigAnnotationField annotationField : annotationFields) {
- nameToAnnotationField.put(annotationField.getName(),
- annotationField);
- }
-
- for (DexMethod method : methods) {
- SigAnnotationField annotationField = nameToAnnotationField
- .get(method.getName());
- annotationField.setAnnotations(convertAnnotations(method
- .getAnnotations()));
- }
- }
-
-
- private Set<SigAnnotationField> convertAnnotationFields(
- List<DexMethod> list, Map<String, Object> mappings) {
- Set<SigAnnotationField> annotationfields =
- new HashSet<SigAnnotationField>();
- for (DexMethod dexMethod : list) {
- if (isVisible(dexMethod, visibility)) {
- annotationfields.add(convertAnnotationField(dexMethod, mappings
- .get(dexMethod.getName())));
- }
- }
- return annotationfields;
- }
-
- private SigAnnotationField convertAnnotationField(DexMethod dexMethod,
- Object defaultValue) {
- SigAnnotationField annotationField = new SigAnnotationField(dexMethod
- .getName());
- annotationField.setDefaultValue(defaultValue);
- annotationField.setModifiers(getModifier(dexMethod.getModifiers()));
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- annotationField.setType(parser.parseNonGenericType(dexMethod
- .getReturnType()));
- return annotationField;
- }
-
- private IEnumConstant convertEnumConstant(DexField dexField) {
- String qualifiedTypeName = getQualifiedName(dexField
- .getDeclaringClass().getName());
- SigEnumConstant enumConstant = elementPool.getEnumConstant(
- qualifiedTypeName, dexField.getName());
- Set<Modifier> modifiers = getModifier(dexField.getModifiers());
- modifiers.add(Modifier.STATIC);
- enumConstant.setModifiers(modifiers);
-
- String typePackageName = getPackageName(dexField.getType());
- String typeName = getClassName(dexField.getType());
- enumConstant.setType(factory.getClassReference(typePackageName,
- typeName));
- enumConstant.setAnnotations(convertAnnotations(dexField
- .getAnnotations()));
- return enumConstant;
- }
-
- private Set<SigField> convertFields(List<DexField> dexFields) {
- Set<SigField> fields = new HashSet<SigField>();
- for (DexField dexField : dexFields) {
- if (isVisible(dexField, visibility)) {
- fields.add(convertField(dexField));
- }
- }
- return fields;
- }
-
- private SigField convertField(DexField dexField) {
- String qualTypeName = getQualifiedName(dexField.getDeclaringClass()
- .getName());
- SigField field = elementPool.getField(qualTypeName, dexField.getName());
-
- field.setModifiers(getModifier(dexField.getModifiers()));
-
- field.setAnnotations(convertAnnotations(dexField.getAnnotations()));
-
- if (hasGenericSignature(dexField)) {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- String declaringClassPackageName = getPackageName(dexField
- .getDeclaringClass().getName());
- String declaringClassName = getClassName(dexField
- .getDeclaringClass().getName());
-
- parser.parseForField(factory.getClass(declaringClassPackageName,
- declaringClassName), getGenericSignature(dexField));
- field.setType(parser.fieldType);
- } else {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- field.setType(parser.parseNonGenericType(dexField.getType()));
- }
-
- return field;
- }
-
- /**
- * Converts a set of {@link DexMethod} to a set of corresponding
- * {@link IConstructor}. This method ignores methods which are not
- * constructors.
- *
- * @param methods
- * the {@link DexMethod}s to convert
- * @return the corresponding {@link IConstructor}s
- */
- private Set<SigConstructor> convertConstructors(List<DexMethod> methods) {
- Set<SigConstructor> constructors = new HashSet<SigConstructor>();
- for (DexMethod method : methods) {
- if (isConstructor(method) && isVisible(method, visibility)) {
- constructors.add(convertConstructor(method));
- }
- }
- return constructors;
- }
-
- /**
- * Converts a set of {@link DexMethod} to a set of corresponding
- * {@link DexMethod}. This method ignores methods which are constructors.
- *
- * @param methods
- * the {@link DexMethod}s to convert
- * @return the corresponding {@link IConstructor}s
- */
- private Set<SigMethod> convertMethods(List<DexMethod> methods) {
- Set<SigMethod> sigMethods = new HashSet<SigMethod>();
- for (DexMethod method : methods) {
- if (isMethod(method) && isVisible(method, visibility)) {
- sigMethods.add(convertMethod(method));
- }
- }
- return sigMethods;
- }
-
- /**
- * Converts a dexMethod which must be a constructor to the corresponding
- * {@link SigConstructor} instance.
- *
- * @param dexMethod
- * the dex constructor to convert
- * @return the corresponding {@link SigConstructor}
- */
- public SigConstructor convertConstructor(DexMethod dexMethod) {
- String declaringClassName = getClassName(dexMethod.getDeclaringClass()
- .getName());
-
- SigConstructor constructor = new SigConstructor(declaringClassName);
- constructor.setModifiers(getModifier(dexMethod.getModifiers()));
- String declaringClassPackageName = getPackageName(dexMethod
- .getDeclaringClass().getName());
-
-
- SigClassDefinition declaringClass = factory.getClass(
- declaringClassPackageName, declaringClassName);
- constructor.setDeclaringClass(declaringClass);
-
- // Annotations
- constructor.setAnnotations(convertAnnotations(dexMethod
- .getAnnotations()));
-
- if (hasGenericSignature(dexMethod)) {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- parser.parseForConstructor(constructor,
- getGenericSignature(dexMethod));
-
- // type parameters
- constructor.setTypeParameters(parser.formalTypeParameters);
-
- // parameters
- // generic parameter types parameters
- List<DexParameter> dexParameters = dexMethod.getParameters();
- List<IParameter> parameters = new ArrayList<IParameter>(
- parser.parameterTypes.size());
- Iterator<DexParameter> iterator = dexParameters.iterator();
- for (ITypeReference parameterType : parser.parameterTypes) {
- SigParameter parameter = new SigParameter(parameterType);
- iterator.hasNext();
- DexParameter dexParam = iterator.next();
- parameter.setAnnotations(convertAnnotations(dexParam
- .getAnnotations()));
- parameters.add(parameter);
- }
-
- constructor.setParameters(parameters);
-
- // exceptions
- constructor.setExceptions(new HashSet<ITypeReference>(
- parser.exceptionTypes));
-
- } else {
- convertNonGenericExecutableMember(constructor, dexMethod);
-
- // remove first parameter of non static inner class constructors
- // implicit outer.this reference
- if (declaringClass.getDeclaringClass() != null) {
- if (!declaringClass.getModifiers().contains(Modifier.STATIC)) {
- if (constructor.getParameters().isEmpty()) {
- throw new IllegalStateException(
- "Expected at least one parameter!");
- }
- IParameter first = constructor.getParameters().remove(0);
- String enclosingName = declaringClass.getDeclaringClass()
- .getName();
- String firstParameterTypeName = ((IClassReference) first
- .getType()).getClassDefinition().getName();
- if (!enclosingName.equals(firstParameterTypeName))
- throw new IllegalStateException(
- "Expected first constructor parameter of type "
- + enclosingName);
- }
- }
- }
-
- addExceptions(constructor, dexMethod);
- return constructor;
- }
-
- public SigMethod convertMethod(DexMethod dexMethod) {
- SigMethod method = new SigMethod(dexMethod.getName());
- method.setModifiers(getModifier(dexMethod.getModifiers()));
-
- String declaringClassPackageName = getPackageName(dexMethod
- .getDeclaringClass().getName());
- String declaringClassName = getClassName(dexMethod.getDeclaringClass()
- .getName());
-
- method.setDeclaringClass(factory.getClass(declaringClassPackageName,
- declaringClassName));
-
- // Annotations
- method.setAnnotations(convertAnnotations(dexMethod.getAnnotations()));
-
- if (hasGenericSignature(dexMethod)) {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- parser.parseForMethod(method, getGenericSignature(dexMethod));
-
- // type parameters
- method.setTypeParameters(parser.formalTypeParameters);
-
- // generic parameter types parameters
- List<DexParameter> dexParameters = dexMethod.getParameters();
- List<IParameter> parameters = new ArrayList<IParameter>(
- parser.parameterTypes.size());
- Iterator<DexParameter> iterator = dexParameters.iterator();
- for (ITypeReference parameterType : parser.parameterTypes) {
- SigParameter parameter = new SigParameter(parameterType);
- iterator.hasNext();
- DexParameter dexParam = iterator.next();
- parameter.setAnnotations(convertAnnotations(dexParam
- .getAnnotations()));
- parameters.add(parameter);
- }
- method.setParameters(parameters);
-
- // exceptions
- method.setExceptions(new HashSet<ITypeReference>(
- parser.exceptionTypes));
- method.setReturnType(parser.returnType);
-
- } else {
- convertNonGenericExecutableMember(method, dexMethod);
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- ITypeReference type = parser.parseNonGenericReturnType(dexMethod
- .getReturnType());
- method.setReturnType(type);
- }
- addExceptions(method, dexMethod);
- return method;
- }
-
- private void addExceptions(SigExecutableMember member,
- DexMethod dexMethod) {
- if (declaresExceptions(dexMethod)) {
- String exceptionSignature = getExceptionSignature(dexMethod);
- Set<String> exceptionTypeNames = splitTypeList(exceptionSignature);
- Set<ITypeReference> exceptions = new HashSet<ITypeReference>();
-
- for (String exTypeName : exceptionTypeNames) {
- String packageName = getPackageName(exTypeName);
- String className = getClassName(exTypeName);
- exceptions.add(factory
- .getClassReference(packageName, className));
- }
- member.setExceptions(exceptions);
- } else {
- member.setExceptions(EMPTY_EXCEPTIONS);
- }
- }
-
- private void convertNonGenericExecutableMember(SigExecutableMember member,
- DexMethod dexMethod) {
- List<DexParameter> dexParameters = dexMethod.getParameters();
- List<IParameter> parameters = new ArrayList<IParameter>(dexParameters
- .size());
-
- for (DexParameter dexParameter : dexParameters) {
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- ITypeReference type = parser.parseNonGenericType(dexParameter
- .getTypeName());
- SigParameter parameter = new SigParameter(type);
- parameters.add(parameter);
- // Annotations
- parameter.setAnnotations(convertAnnotations(dexParameter
- .getAnnotations()));
- }
- member.setParameters(parameters);
-
- member.setTypeParameters(EMPTY_TYPE_VARIABLES);
-
- // if (declaresExceptions(dexMethod)) {
- // String exceptionSignature = getExceptionSignature(dexMethod);
- // Set<String> exceptionTypeNames = splitTypeList(exceptionSignature);
- // Set<IType> exceptions = new HashSet<IType>();
- //
- // for (String exTypeName : exceptionTypeNames) {
- // String packageName = getPackageName(exTypeName);
- // String className = getClassName(exTypeName);
- // exceptions.add(factory.getClass(packageName, className));
- // }
- // member.setExceptions(exceptions);
- // } else {
- // member.setExceptions(EMPTY_EXCEPTIONS);
- // }
- }
-
- /**
- * Converts a set of {@link DexAnnotation} to a set of corresponding
- * {@link SigAnnotation}.
- *
- * @param dexAnnotations
- * the {@link DexAnnotation}s to convert
- * @return the corresponding {@link SigAnnotation}s
- */
- private Set<IAnnotation> convertAnnotations(
- Set<DexAnnotation> dexAnnotations) {
- Set<IAnnotation> annotations = new HashSet<IAnnotation>();
- for (DexAnnotation dexAnnotation : dexAnnotations) {
- if (!isInternalAnnotation(dexAnnotation)) {
- annotations.add(convertAnnotation(dexAnnotation));
- }
- }
- return annotations;
- }
-
- /**
- * Converts a {@link DexAnnotation} to the corresponding
- * {@link SigAnnotation}.
- *
- * @param dexAnnotation
- * the {@link DexAnnotation} to convert
- * @return the corresponding {@link SigAnnotation}
- */
- protected SigAnnotation convertAnnotation(DexAnnotation dexAnnotation) {
- SigAnnotation sigAnnotation = new SigAnnotation();
- String packageName = getPackageName(dexAnnotation.getTypeName());
- String className = getClassName(dexAnnotation.getTypeName());
- sigAnnotation
- .setType(factory.getClassReference(packageName, className));
- sigAnnotation.setElements(convertAnnotationElements(dexAnnotation
- .getAttributes()));
- return sigAnnotation;
- }
-
- private Set<IAnnotationElement> convertAnnotationElements(
- List<DexAnnotationAttribute> attributes) {
- Set<IAnnotationElement> annotationAttributes =
- new HashSet<IAnnotationElement>();
- for (DexAnnotationAttribute dexAnnotationAttribute : attributes) {
- annotationAttributes
- .add(convertAnnotationAttribute(dexAnnotationAttribute));
- }
- return annotationAttributes;
- }
-
- private IAnnotationElement convertAnnotationAttribute(
- DexAnnotationAttribute dexAnnotationAttribute) {
-
- SigAnnotationElement sigElement = new SigAnnotationElement();
- String nameOfField = dexAnnotationAttribute.getName();
-
-
- String typeName = dexAnnotationAttribute.getAnnotation().getTypeName();
- SigClassDefinition annotationClass = factory.getClass(
- getPackageName(typeName), getClassName(typeName));
- if (!Uninitialized.isInitialized(
- annotationClass.getAnnotationFields())) {
- initializeClass(getPackageName(typeName), getClassName(typeName));
- }
- for (IAnnotationField field : annotationClass.getAnnotationFields()) {
- if (nameOfField.equals(field.getName())) {
- sigElement.setDeclaringField(field);
- }
- }
-
- sigElement.setValue(convertEncodedValue(dexAnnotationAttribute
- .getEncodedValue()));
- return sigElement;
- }
-
- @SuppressWarnings("unchecked")
- private Object convertEncodedValue(DexEncodedValue dexEnodedValue) {
- Object value = null;
- switch (dexEnodedValue.getType()) {
- case VALUE_INT:
- case VALUE_BOOLEAN:
- case VALUE_BYTE:
- case VALUE_CHAR:
- case VALUE_DOUBLE:
- case VALUE_FLOAT:
- case VALUE_LONG:
- case VALUE_NULL:
- case VALUE_STRING:
- case VALUE_SHORT:
- value = dexEnodedValue.getValue();
- break;
- case VALUE_ARRAY: {
- List<DexEncodedValue> dexValues =
- (List<DexEncodedValue>) dexEnodedValue.getValue();
- Object[] arrayValues = new Object[dexValues.size()];
- int i = 0;
- for (DexEncodedValue dexValue : dexValues) {
- arrayValues[i++] = convertEncodedValue(dexValue);
- }
- value = arrayValues;
- break;
- }
- case VALUE_ANNOTATION: {
- DexEncodedAnnotation annotation =
- (DexEncodedAnnotation) dexEnodedValue.getValue();
- SigAnnotation sigAnnotation = new SigAnnotation();
- String packageName = getPackageName(annotation.getTypeName());
- String className = getClassName(annotation.getTypeName());
- sigAnnotation.setType(factory.getClassReference(packageName,
- className));
-
- sigAnnotation.setElements(convertAnnotationElements(annotation
- .getValue()));
- value = sigAnnotation;
- break;
- }
- case VALUE_FIELD: {
- String fieldDesc = (String) dexEnodedValue.getValue();
- // FORMAT La/b/E;!CONSTANT
- String[] typeAndFieldName = fieldDesc.split("!");
- String typeName = typeAndFieldName[0];
- String fieldName = typeAndFieldName[1];
- value = elementPool.getField(getQualifiedName(typeName), fieldName);
- break;
- }
- case VALUE_ENUM: {
- String fieldDesc = (String) dexEnodedValue.getValue();
- // FORMAT La/b/E;!CONSTANT
- String[] typeAndFieldName = fieldDesc.split("!");
- String typeName = typeAndFieldName[0];
- String fieldName = typeAndFieldName[1];
- value = elementPool.getEnumConstant(getQualifiedName(typeName),
- fieldName);
- break;
- }
- case VALUE_TYPE: {
- String typeName = (String) dexEnodedValue.getValue();
- GenericSignatureParser parser = new GenericSignatureParser(factory,
- this);
- value = parser.parseNonGenericReturnType(typeName);
- break;
- }
- default:
- throw new IllegalStateException();
- }
- return value;
- }
-
- public IClassDefinition initializeClass(String packageName,
- String className) {
- String dexName = getDexName(packageName, className);
- DexClass dexClass = dexNameToDexClass.get(dexName);
- return convertClass(dexClass);
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/DexUtil.java b/tools/signature-tools/src/signature/converter/dex/DexUtil.java
deleted file mode 100644
index f661af2..0000000
--- a/tools/signature-tools/src/signature/converter/dex/DexUtil.java
+++ /dev/null
@@ -1,600 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IClassDefinition;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigPackage;
-import signature.model.util.ModelUtil;
-import dex.reader.DexBuffer;
-import dex.reader.DexFileReader;
-import dex.structure.DexAnnotatedElement;
-import dex.structure.DexAnnotation;
-import dex.structure.DexAnnotationAttribute;
-import dex.structure.DexClass;
-import dex.structure.DexEncodedValue;
-import dex.structure.DexField;
-import dex.structure.DexFile;
-import dex.structure.DexMethod;
-
-
-public class DexUtil {
-
- private static final String PACKAGE_INFO = "package-info";
- private static final String THROWS_ANNOTATION =
- "Ldalvik/annotation/Throws;";
- private static final String SIGNATURE_ANNOTATION =
- "Ldalvik/annotation/Signature;";
- private static final String ANNOTATION_DEFAULT_ANNOTATION =
- "Ldalvik/annotation/AnnotationDefault;";
- private static final String ENCLOSING_CLASS_ANNOTATION =
- "Ldalvik/annotation/EnclosingClass;";
- private static final String ENCLOSING_METHOD_ANNOTATION =
- "Ldalvik/annotation/EnclosingMethod;";
- private static final String INNER_CLASS_ANNOTATION =
- "Ldalvik/annotation/InnerClass;";
- private static final String MEMBER_CLASS_ANNOTATION =
- "Ldalvik/annotation/MemberClasses;";
- private static final String JAVA_LANG_OBJECT = "Ljava/lang/Object;";
-
- private static final Set<String> INTERNAL_ANNOTATION_NAMES;
-
- static {
- Set<String> tmp = new HashSet<String>();
- tmp.add(THROWS_ANNOTATION);
- tmp.add(SIGNATURE_ANNOTATION);
- tmp.add(ANNOTATION_DEFAULT_ANNOTATION);
- tmp.add(ENCLOSING_CLASS_ANNOTATION);
- tmp.add(ENCLOSING_METHOD_ANNOTATION);
- tmp.add(INNER_CLASS_ANNOTATION);
- tmp.add(MEMBER_CLASS_ANNOTATION);
- INTERNAL_ANNOTATION_NAMES = Collections.unmodifiableSet(tmp);
- }
-
- private DexUtil() {
- // not constructable from outside
- }
-
- /**
- * "La/b/c/A;" -> "a.b.c" "LA;" -> "" empty string
- *
- * @param classIdentifier
- * @return the package name
- */
- public static String getPackageName(String classIdentifier) {
- String name = removeTrailingSemicolon(removeHeadingL(classIdentifier));
- return ModelUtil.getPackageName(name.replace("/", "."));
- }
-
- /**
- * "La/b/c/A;" -> "A" "LA;" -> "A"
- *
- * @param classIdentifier
- * the dalvik internal identifier
- * @return the class name
- */
- public static String getClassName(String classIdentifier) {
- String name = removeTrailingSemicolon(removeHeadingL(classIdentifier));
- return ModelUtil.getClassName(name.replace("/", ".")).replace('$', '.');
- }
-
- public static String getQualifiedName(String classIdentifier) {
- String name = removeTrailingSemicolon(removeHeadingL(classIdentifier));
- return name.replace('/', '.');
- }
-
- private static String removeHeadingL(String className) {
- assert className.startsWith("L");
- return className.substring(1);
- }
-
- private static String removeTrailingSemicolon(String className) {
- assert className.endsWith(";");
- return className.substring(0, className.length() - 1);
- }
-
- public static String getDexName(String packageName, String className) {
- return "L" + packageName.replace('.', '/') + "/"
- + className.replace('.', '$') + ";";
- }
-
- public static String getDexName(IClassDefinition sigClass) {
- return getDexName(sigClass.getPackageName(), sigClass.getName());
- }
-
- /**
- * Returns correct modifiers for inner classes
- */
- public static int getClassModifiers(DexClass clazz) {
- int modifiers = 0;
- if (isInnerClass(clazz)) {
- Integer accessFlags = (Integer) getAnnotationAttributeValue(
- getAnnotation(clazz, INNER_CLASS_ANNOTATION),
- "accessFlags");
- modifiers = accessFlags.intValue();
- } else {
- modifiers = clazz.getModifiers();
- }
- return modifiers;
- }
-
- /**
- * Returns a set containing all modifiers for the given int.
- *
- * @param mod
- * the original bit coded modifiers as specified by
- * {@link java.lang.reflect.Modifier}
- * @return a set containing {@link signature.model.Modifier} elements
- */
- public static Set<Modifier> getModifier(int mod) {
- Set<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
- if (java.lang.reflect.Modifier.isAbstract(mod))
- modifiers.add(Modifier.ABSTRACT);
- if (java.lang.reflect.Modifier.isFinal(mod))
- modifiers.add(Modifier.FINAL);
- // if (java.lang.reflect.Modifier.isNative(mod))
- // modifiers.add(Modifier.NATIVE);
- if (java.lang.reflect.Modifier.isPrivate(mod))
- modifiers.add(Modifier.PRIVATE);
- if (java.lang.reflect.Modifier.isProtected(mod))
- modifiers.add(Modifier.PROTECTED);
- if (java.lang.reflect.Modifier.isPublic(mod))
- modifiers.add(Modifier.PUBLIC);
- if (java.lang.reflect.Modifier.isStatic(mod))
- modifiers.add(Modifier.STATIC);
- // if (java.lang.reflect.Modifier.isStrict(mod))
- // modifiers.add(Modifier.STRICT);
- // if (java.lang.reflect.Modifier.isSynchronized(mod))
- // modifiers.add(Modifier.SYNCHRONIZED);
- // if (java.lang.reflect.Modifier.isTransient(mod))
- // modifiers.add(Modifier.TRANSIENT);
- if (java.lang.reflect.Modifier.isVolatile(mod))
- modifiers.add(Modifier.VOLATILE);
-
- return modifiers;
- }
-
- /**
- * Returns true if the given class is an enumeration, false otherwise.
- *
- * @param dexClass
- * the DexClass under test
- * @return true if the given class is an enumeration, false otherwise
- */
- public static boolean isEnum(DexClass dexClass) {
- return (getClassModifiers(dexClass) & 0x4000) > 0;
- }
-
- /**
- * Returns true if the given class is an interface, false otherwise.
- *
- * @param dexClass
- * the DexClass under test
- * @return true if the given class is an interface, false otherwise
- */
- public static boolean isInterface(DexClass dexClass) {
- int modifiers = getClassModifiers(dexClass);
- return java.lang.reflect.Modifier.isInterface(modifiers);
- }
-
- /**
- * Returns true if the given class is an annotation, false otherwise.
- *
- * @param dexClass
- * the DexClass under test
- * @return true if the given class is an annotation, false otherwise
- */
- public static boolean isAnnotation(DexClass dexClass) {
- return (getClassModifiers(dexClass) & 0x2000) > 0;
- }
-
- public static boolean isSynthetic(int modifier) {
- return (modifier & 0x1000) > 0;
- }
-
- /**
- * Returns the Kind of the given DexClass.
- *
- * @param dexClass
- * the DexClass under test
- * @return the Kind of the given class
- */
- public static Kind getKind(DexClass dexClass) {
- // order of branches is crucial since a annotation is also an interface
- if (isEnum(dexClass)) {
- return Kind.ENUM;
- } else if (isAnnotation(dexClass)) {
- return Kind.ANNOTATION;
- } else if (isInterface(dexClass)) {
- return Kind.INTERFACE;
- } else {
- return Kind.CLASS;
- }
- }
-
- /**
- * Returns whether the specified annotated element has an annotation with
- * type "Ldalvik/annotation/Throws;".
- *
- * @param annotatedElement
- * the annotated element to check
- * @return <code>true</code> if the given annotated element has the
- * mentioned annotation, false otherwise
- */
- public static boolean declaresExceptions(
- DexAnnotatedElement annotatedElement) {
- return getAnnotation(annotatedElement, THROWS_ANNOTATION) != null;
- }
-
- /**
- * Returns the throws signature if the given element has such an annotation,
- * null otherwise.
- *
- * @param annotatedElement
- * the annotated element
- * @return he generic signature if the given element has such an annotation,
- * null otherwise
- */
- @SuppressWarnings("unchecked")
- public static String getExceptionSignature(
- DexAnnotatedElement annotatedElement) {
- DexAnnotation annotation = getAnnotation(annotatedElement,
- THROWS_ANNOTATION);
- if (annotation != null) {
- List<DexEncodedValue> value =
- (List<DexEncodedValue>) getAnnotationAttributeValue(
- annotation, "value");
- return concatEncodedValues(value);
- }
- return null;
- }
-
- /**
- * Splits a list of types:
- * "Ljava/io/IOException;Ljava/lang/IllegalStateException;" <br>
- * into separate type designators: <br>
- * "Ljava/io/IOException;" , "Ljava/lang/IllegalStateException;"
- *
- * @param typeList
- * the type list
- * @return a set of type designators
- */
- public static Set<String> splitTypeList(String typeList) {
- String[] split = typeList.split(";");
- Set<String> separateTypes = new HashSet<String>();
- for (String string : split) {
- separateTypes.add(string + ";");// add semicolon again
- }
- return separateTypes;
- }
-
- /**
- * Returns whether the specified annotated element has an annotation with
- * type "Ldalvik/annotation/Signature;".
- *
- * @param annotatedElement
- * the annotated element to check
- * @return <code>true</code> if the given annotated element has the
- * mentioned annotation, false otherwise
- */
- public static boolean hasGenericSignature(
- DexAnnotatedElement annotatedElement) {
- return getAnnotation(annotatedElement, SIGNATURE_ANNOTATION) != null;
- }
-
- /**
- * Returns the generic signature if the given element has such an
- * annotation, null otherwise.
- *
- * @param annotatedElement
- * the annotated element
- * @return he generic signature if the given element has such an annotation,
- * null otherwise
- */
- @SuppressWarnings("unchecked")
- public static String getGenericSignature(
- DexAnnotatedElement annotatedElement) {
- DexAnnotation annotation = getAnnotation(annotatedElement,
- SIGNATURE_ANNOTATION);
- if (annotation != null) {
- List<DexEncodedValue> value =
- (List<DexEncodedValue>) getAnnotationAttributeValue(
- annotation, "value");
- return concatEncodedValues(value);
- }
- return null;
- }
-
- /**
- * Returns whether the specified annotated element has an annotation with
- * type "Ldalvik/annotation/AnnotationDefault;".
- *
- * @param annotatedElement
- * the annotated element to check
- * @return <code>true</code> if the given annotated element has the
- * mentioned annotation, false otherwise
- */
- public static boolean hasAnnotationDefaultSignature(
- DexAnnotatedElement annotatedElement) {
- return getAnnotation(
- annotatedElement, ANNOTATION_DEFAULT_ANNOTATION)!= null;
- }
-
- /**
- * Returns a mapping form annotation attribute name to its default value.
- *
- * @param dexClass
- * the class defining a annotation
- * @return a mapping form annotation attribute name to its default value
- */
- public static DexAnnotation getDefaultMappingsAnnotation(
- DexClass dexClass) {
- return getAnnotation(dexClass, ANNOTATION_DEFAULT_ANNOTATION);
- }
-
- /**
- * Returns the annotation with the specified type from the given element or
- * null if no such annotation is available.
- *
- * @param element
- * the annotated element
- * @param annotationType
- * the dex internal name of the annotation type
- * @return the annotation with the specified type or null if not present
- */
- public static DexAnnotation getAnnotation(DexAnnotatedElement element,
- String annotationType) {
- assert element != null;
- assert annotationType != null;
-
- for (DexAnnotation anno : element.getAnnotations()) {
- if (annotationType.equals(anno.getTypeName())) {
- return anno;
- }
- }
- return null;
- }
-
- /**
- * Returns the value for the specified attribute name of the given
- * annotation or null if not present.
- *
- * @param annotation
- * the annotation
- * @param attributeName
- * the name of the attribute
- * @return the value for the specified attribute
- */
- public static Object getAnnotationAttributeValue(DexAnnotation annotation,
- String attributeName) {
- for (DexAnnotationAttribute dexAnnotationAttribute : annotation
- .getAttributes()) {
- if (attributeName.equals(dexAnnotationAttribute.getName())) {
- return dexAnnotationAttribute.getEncodedValue().getValue();
- }
- }
- return null;
- }
-
- private static String concatEncodedValues(List<DexEncodedValue> values) {
- StringBuilder builder = new StringBuilder();
- for (DexEncodedValue string : values) {
- builder.append(string.getValue());
- }
- return builder.toString();
- }
-
- /**
- * Returns true if the given method is a constructor, false otherwise.
- *
- * @param method
- * the method to test
- * @return true if the given method is a constructor, false otherwise
- */
- public static boolean isConstructor(DexMethod method) {
- return "<init>".equals(method.getName());
- }
-
- /**
- * Returns true if the given method is a static constructor, false
- * otherwise.
- *
- * @param method
- * the method to test
- * @return true if the given method is a static constructor, false otherwise
- */
- public static boolean isStaticConstructor(DexMethod method) {
- return "<clinit>".equals(method.getName());
- }
-
- public static boolean isMethod(DexMethod method) {
- return !isConstructor(method) && !isStaticConstructor(method);
- }
-
- /**
- * Returns the package-info class for the given package.
- *
- * @param aPackage
- * the package
- * @return the class called "package-info" or null, if not available
- */
- public static IClassDefinition findPackageInfo(SigPackage aPackage) {
- for (IClassDefinition clazz : aPackage.getClasses()) {
- if (PACKAGE_INFO.equals(clazz.getName())) {
- return clazz;
- }
- }
- return null;
- }
-
- public static boolean isPackageInfo(DexClass clazz) {
- return PACKAGE_INFO.equals(getClassName(clazz.getName()));
- }
-
- public static boolean isInternalAnnotation(DexAnnotation dexAnnotation) {
- return INTERNAL_ANNOTATION_NAMES.contains(dexAnnotation.getTypeName());
- }
-
- /**
- * An InnerClass annotation is attached to each class which is defined in
- * the lexical scope of another class's definition. Any class which has this
- * annotation must also have either an EnclosingClass annotation or an
- * EnclosingMethod annotation.
- */
- public static boolean isInnerClass(DexClass clazz) {
- return getAnnotation(clazz, INNER_CLASS_ANNOTATION) != null;
- }
-
- /**
- * An EnclosingClass annotation is attached to each class which is either
- * defined as a member of another class, per se, or is anonymous but not
- * defined within a method body (e.g., a synthetic inner class). Every class
- * that has this annotation must also have an InnerClass annotation.
- * Additionally, a class may not have both an EnclosingClass and an
- * EnclosingMethod annotation.
- */
- public static boolean isEnclosingClass(DexClass clazz) {
- return getAnnotation(clazz, ENCLOSING_CLASS_ANNOTATION) != null;
- }
-
- public static boolean declaresMemberClasses(DexClass dexClass) {
- return getAnnotation(dexClass, MEMBER_CLASS_ANNOTATION) != null;
- }
-
- @SuppressWarnings("unchecked")
- public static Set<String> getMemberClassNames(DexClass dexClass) {
- DexAnnotation annotation = getAnnotation(dexClass,
- MEMBER_CLASS_ANNOTATION);
- List<DexEncodedValue> enclosedClasses =
- (List<DexEncodedValue>) getAnnotationAttributeValue(
- annotation, "value");
- Set<String> enclosedClassesNames = new HashSet<String>();
- for (DexEncodedValue string : enclosedClasses) {
- enclosedClassesNames.add((String) string.getValue());
- }
- return enclosedClassesNames;
- }
-
-
- public static String getEnclosingClassName(DexClass dexClass) {
- DexAnnotation annotation = getAnnotation(dexClass,
- ENCLOSING_CLASS_ANNOTATION);
- String value = (String) getAnnotationAttributeValue(annotation,
- "value");
- return value;
- }
-
- public static boolean convertAnyWay(DexClass dexClass) {
- return !isSynthetic(getClassModifiers(dexClass))
- && !isAnonymousClassName(dexClass.getName())
- || isPackageInfo(dexClass);
- }
-
- public static boolean isVisible(DexClass dexClass, Visibility visibility) {
- // package info is always visible
- if (isPackageInfo(dexClass)) {
- return true;
- }
-
- if (isDeclaredInMethod(dexClass)) {
- return false;
- }
-
- if (isAnonymousClassName(dexClass.getName())) {
- return false;
- }
-
- int modifiers = getClassModifiers(dexClass);
-
- return isVisible(modifiers, visibility);
- }
-
- private static boolean isDeclaredInMethod(DexClass dexClass) {
- return getAnnotation(dexClass, ENCLOSING_METHOD_ANNOTATION) != null;
- }
-
- /**
- * Returns whether the given dex identifier is an anonymous class name.
- * Format: La/b/C$1;
- *
- * @param dexName
- * the name to analyze
- * @return whether the given dex identifier is an anonymous class name
- */
- public static boolean isAnonymousClassName(String dexName) {
- int index = dexName.lastIndexOf('$');
- return (index != 0) ? Character.isDigit(dexName.charAt(index + 1))
- : false;
- }
-
- public static boolean isVisible(DexField dexField, Visibility visibility) {
- return isVisible(dexField.getModifiers(), visibility);
- }
-
- public static boolean isVisible(DexMethod dexMethod,
- Visibility visibility) {
- return isVisible(dexMethod.getModifiers(), visibility);
- }
-
- private static boolean isVisible(int modifiers, Visibility visibility) {
-
- if (isSynthetic(modifiers)) {
- return false;
- }
-
- Set<Modifier> elementModifiers = getModifier(modifiers);
- if (elementModifiers.contains(Modifier.PUBLIC)) {
- return true;
- } else if (elementModifiers.contains(Modifier.PROTECTED)) {
- return visibility == Visibility.PROTECTED
- || visibility == Visibility.PACKAGE
- || visibility == Visibility.PRIVATE;
- } else if (elementModifiers.contains(Modifier.PRIVATE)) {
- return visibility == Visibility.PRIVATE;
- } else {
- return visibility == Visibility.PACKAGE
- || visibility == Visibility.PRIVATE;
- }
- }
-
- public static Set<DexFile> getDexFiles(Set<String> fileNames)
- throws IOException {
- Set<DexFile> parsedFiles = new HashSet<DexFile>();
-
- for (String dexFile : fileNames) {
- DexFileReader reader = new DexFileReader();
- DexBuffer dexBuffer = new DexBuffer(dexFile);
- parsedFiles.add(reader.read(dexBuffer));
- }
- return parsedFiles;
- }
-
-
- public static boolean isJavaLangObject(DexClass dexClass) {
- assert dexClass != null;
- return JAVA_LANG_OBJECT.equals(dexClass.getName());
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/FieldPool.java b/tools/signature-tools/src/signature/converter/dex/FieldPool.java
deleted file mode 100644
index 6587820..0000000
--- a/tools/signature-tools/src/signature/converter/dex/FieldPool.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import signature.model.impl.SigEnumConstant;
-import signature.model.impl.SigField;
-
-public class FieldPool {
-
- private Map<FieldKey, SigField> fieldStore;
- private Map<FieldKey, SigEnumConstant> constantStore;
-
- public FieldPool() {
- fieldStore = new HashMap<FieldKey, SigField>();
- constantStore = new HashMap<FieldKey, SigEnumConstant>();
- }
-
- private static class FieldKey {
- private final String qualifiedClassName;
- private final String fieldName;
-
- public FieldKey(String qualifiedClassName, String fieldName) {
- this.qualifiedClassName = qualifiedClassName;
- this.fieldName = fieldName;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = prime * fieldName.hashCode();
- result = prime * result + qualifiedClassName.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- FieldKey other = (FieldKey) obj;
- if (!fieldName.equals(other.fieldName)) {
- return false;
- }
- if (!qualifiedClassName.equals(other.qualifiedClassName)) {
- return false;
- }
- return true;
- }
- }
-
- public SigField getField(String qualifiedClassName, String fieldName) {
- FieldKey key = new FieldKey(qualifiedClassName, fieldName);
- SigField sigField = fieldStore.get(key);
- if (sigField == null) {
- sigField = new SigField(fieldName);
- fieldStore.put(key, sigField);
- }
- return sigField;
- }
-
- public SigEnumConstant getEnumConstant(String qualifiedName,
- String fieldName) {
- FieldKey key = new FieldKey(qualifiedName, fieldName);
- SigEnumConstant sigField = constantStore.get(key);
- if (sigField == null) {
- sigField = new SigEnumConstant(fieldName);
- constantStore.put(key, sigField);
- }
- return sigField;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/GenericSignatureParser.java b/tools/signature-tools/src/signature/converter/dex/GenericSignatureParser.java
deleted file mode 100644
index 773e2fc..0000000
--- a/tools/signature-tools/src/signature/converter/dex/GenericSignatureParser.java
+++ /dev/null
@@ -1,651 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import static signature.converter.dex.DexUtil.getClassName;
-import static signature.converter.dex.DexUtil.getPackageName;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IGenericDeclaration;
-import signature.model.IMethod;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.impl.SigArrayType;
-import signature.model.impl.SigParameterizedType;
-import signature.model.impl.SigPrimitiveType;
-import signature.model.impl.SigTypeVariableDefinition;
-import signature.model.impl.SigWildcardType;
-import signature.model.impl.Uninitialized;
-import signature.model.util.ITypeFactory;
-
-import java.lang.reflect.GenericSignatureFormatError;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Implements a parser for the generics signature attribute. Uses a top-down,
- * recursive descent parsing approach for the following grammar:
- *
- * <pre>
- * ClassSignature ::=
- * OptFormalTypeParams SuperclassSignature {SuperinterfaceSignature}.
- * SuperclassSignature ::= ClassTypeSignature.
- * SuperinterfaceSignature ::= ClassTypeSignature.
- *
- * OptFormalTypeParams ::=
- * ["<" FormalTypeParameter {FormalTypeParameter} ">"].
- *
- * FormalTypeParameter ::= Ident ClassBound {InterfaceBound}.
- * ClassBound ::= ":" [FieldTypeSignature].
- * InterfaceBound ::= ":" FieldTypeSignature.
- *
- * FieldTypeSignature ::=
- * ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature.
- * ArrayTypeSignature ::= "[" TypSignature.
- *
- * ClassTypeSignature ::=
- * "L" {Ident "/"} Ident OptTypeArguments {"." Ident OptTypeArguments} ";".
- *
- * OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">".
- *
- * TypeArgument ::= ([WildcardIndicator] FieldTypeSignature) | "*".
- * WildcardIndicator ::= "+" | "-".
- *
- * TypeVariableSignature ::= "T" Ident ";".
- *
- * TypSignature ::= FieldTypeSignature | BaseType.
- * BaseType ::= "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z".
- *
- * MethodTypeSignature ::=
- * OptFormalTypeParams "(" {TypeSignature} ")" ReturnType {ThrowsSignature}.
- * ThrowsSignature ::= ("^" ClassTypeSignature) | ("^" TypeVariableSignature).
- *
- * ReturnType ::= TypSignature | VoidDescriptor.
- * VoidDescriptor ::= "V".
- * </pre>
- */
-public class GenericSignatureParser {
-
- public List<ITypeReference> exceptionTypes;
- public List<ITypeReference> parameterTypes;
- public List<ITypeVariableDefinition> formalTypeParameters;
- public ITypeReference returnType;
- public ITypeReference fieldType;
- public List<ITypeReference> interfaceTypes;
- public ITypeReference superclassType;
-
- private IGenericDeclaration genericDecl;
-
- /*
- * Parser:
- */
- private char symbol; // 0: eof; else valid term symbol or first char of
- // identifier.
- private String identifier;
-
-
- /*
- * Scanner: eof is private to the scan methods and it's set only when a scan
- * is issued at the end of the buffer.
- */
- private boolean eof;
-
- private char[] buffer;
- private int pos;
-
- private final ITypeFactory factory;
- private final IClassInitializer classFinder;
- private boolean parseForField;
-
-
- public GenericSignatureParser(ITypeFactory factory,
- IClassInitializer classFinder) {
- this.factory = factory;
- this.classFinder = classFinder;
- }
-
- private void setInput(IGenericDeclaration genericDecl, String input) {
- if (input != null) {
- this.genericDecl = genericDecl;
- this.buffer = input.toCharArray();
- this.eof = false;
- scanSymbol();
- } else {
- this.eof = true;
- }
- }
-
- public ITypeReference parseNonGenericType(String typeSignature) {
- setInput(null, typeSignature);
- ITypeReference type = parsePrimitiveType();
- if (type == null) {
- type = parseFieldTypeSignature();
- }
- return type;
- }
-
- public ITypeReference parseNonGenericReturnType(String typeSignature) {
- setInput(null, typeSignature);
- ITypeReference returnType = parsePrimitiveType();
- if (returnType == null) {
- returnType = parseReturnType();
- }
- return returnType;
- }
-
- private ITypeReference parsePrimitiveType() {
- switch (symbol) {
- case 'B':
- scanSymbol();
- return SigPrimitiveType.BYTE_TYPE;
- case 'C':
- scanSymbol();
- return SigPrimitiveType.CHAR_TYPE;
- case 'D':
- scanSymbol();
- return SigPrimitiveType.DOUBLE_TYPE;
- case 'F':
- scanSymbol();
- return SigPrimitiveType.FLOAT_TYPE;
- case 'I':
- scanSymbol();
- return SigPrimitiveType.INT_TYPE;
- case 'J':
- scanSymbol();
- return SigPrimitiveType.LONG_TYPE;
- case 'S':
- scanSymbol();
- return SigPrimitiveType.SHORT_TYPE;
- case 'Z':
- scanSymbol();
- return SigPrimitiveType.BOOLEAN_TYPE;
- default:
- return null;
- }
- }
-
- /**
- * Parses the generic signature of a class and creates the data structure
- * representing the signature.
- *
- * @param classToProcess
- * the GenericDeclaration calling this method
- * @param signature
- * the generic signature of the class
- */
- public void parseForClass(IClassDefinition classToProcess,
- String signature) {
- setInput(classToProcess, signature);
- if (!eof) {
- parseClassSignature();
- } else {
- throw new IllegalStateException("Generic signature is invalid!");
- }
- }
-
- /**
- * Parses the generic signature of a method and creates the data structure
- * representing the signature.
- *
- * @param genericDecl
- * the GenericDeclaration calling this method
- * @param signature
- * the generic signature of the class
- */
- public void parseForMethod(IMethod genericDecl, String signature) {
- setInput(genericDecl, signature);
- if (!eof) {
- parseMethodTypeSignature();
- } else {
- throw new IllegalStateException("Generic signature is invalid!");
- }
- }
-
- /**
- * Parses the generic signature of a constructor and creates the data
- * structure representing the signature.
- *
- * @param genericDecl
- * the GenericDeclaration calling this method
- * @param signature
- * the generic signature of the class
- */
- public void parseForConstructor(IConstructor genericDecl,
- String signature) {
- setInput(genericDecl, signature);
- if (!eof) {
- parseMethodTypeSignature();
- } else {
- throw new IllegalStateException("Generic signature is invalid!");
- }
- }
-
- /**
- * Parses the generic signature of a field and creates the data structure
- * representing the signature.
- *
- * @param genericDecl
- * the GenericDeclaration calling this method
- * @param signature
- * the generic signature of the class
- */
- public void parseForField(IClassDefinition genericDecl, String signature) {
- parseForField = true;
- setInput(genericDecl, signature);
- try {
- if (!eof) {
- this.fieldType = parseFieldTypeSignature();
- } else {
- throw new IllegalStateException(
- "Generic signature is invalid!");
- }
- } finally {
- parseForField = false;
- }
- }
-
- private void parseClassSignature() {
- // ClassSignature ::=
- // OptFormalTypeParameters SuperclassSignature
- // {SuperinterfaceSignature}.
-
- parseOptFormalTypeParameters();
-
- // SuperclassSignature ::= ClassTypeSignature.
- this.superclassType = parseClassTypeSignature();
-
- interfaceTypes = new ArrayList<ITypeReference>(16);
- while (symbol > 0) {
- // SuperinterfaceSignature ::= ClassTypeSignature.
- interfaceTypes.add(parseClassTypeSignature());
- }
- }
-
- private void parseOptFormalTypeParameters() {
- // OptFormalTypeParameters ::=
- // ["<" FormalTypeParameter {FormalTypeParameter} ">"].
-
- List<ITypeVariableDefinition> typeParameters =
- new ArrayList<ITypeVariableDefinition>();
-
- if (symbol == '<') {
- scanSymbol();
- typeParameters.add(parseFormalTypeParameter());
- while ((symbol != '>') && (symbol > 0)) {
- typeParameters.add(parseFormalTypeParameter());
- }
- expect('>');
- }
-
- formalTypeParameters = typeParameters;
- }
-
- private SigTypeVariableDefinition parseFormalTypeParameter() {
- // FormalTypeParameter ::= Ident ClassBound {InterfaceBound}.
-
- scanIdentifier();
- String name = identifier.intern();
- SigTypeVariableDefinition typeVariable = factory.getTypeVariable(name,
- genericDecl);
-
- List<ITypeReference> bounds = new ArrayList<ITypeReference>();
-
- // ClassBound ::= ":" [FieldTypeSignature].
- expect(':');
- if (symbol == 'L' || symbol == '[' || symbol == 'T') {
- bounds.add(parseFieldTypeSignature());
- }
-
- while (symbol == ':') {
- // InterfaceBound ::= ":" FieldTypeSignature.
- scanSymbol();
- bounds.add(parseFieldTypeSignature());
- }
- typeVariable.setUpperBounds(bounds);
- return typeVariable;
- }
-
- /**
- * Returns the generic declaration for the type variable with the specified
- * name.
- *
- * @param variableName
- * the name of the type variable
- * @param declaration
- * the declaration to start searching
- * @return the declaration which defines the specified type variable
- */
- private IGenericDeclaration getDeclarationOfTypeVariable(
- String variableName, IClassDefinition declaration) {
- assert variableName != null;
- assert declaration != null;
-
- if (!Uninitialized.isInitialized(declaration.getTypeParameters())) {
- declaration = classFinder.initializeClass(declaration
- .getPackageName(), declaration.getName());
- }
-
- for (ITypeVariableDefinition typeVariable : declaration
- .getTypeParameters()) {
- if (variableName.equals(typeVariable.getName())) {
- return declaration;
- }
- }
- return getDeclarationOfTypeVariable(variableName, declaration
- .getDeclaringClass());
- }
-
- private ITypeReference parseFieldTypeSignature() {
- // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature
- // | TypeVariableSignature.
-
- switch (symbol) {
- case 'L':
- return parseClassTypeSignature();
- case '[':
- // ArrayTypeSignature ::= "[" TypSignature.
- scanSymbol();
- SigArrayType arrayType = factory.getArrayType(parseTypeSignature());
- return arrayType;
- case 'T':
- return parseTypeVariableSignature();
- default:
- throw new GenericSignatureFormatError();
- }
- }
-
- private ITypeReference parseClassTypeSignature() {
- // ClassTypeSignature ::= "L" {Ident "/"} Ident
- // OptTypeArguments {"." Ident OptTypeArguments} ";".
-
- expect('L');
-
- StringBuilder qualIdent = new StringBuilder("L");
- scanIdentifier();
- while (symbol == '/') {
- scanSymbol();
- qualIdent.append(identifier).append("/");
- scanIdentifier();
- }
-
- qualIdent.append(this.identifier);
-
-
- List<ITypeReference> typeArgs = parseOptTypeArguments();
-
- ITypeReference parentType = null;
-
- String packageName = getPackageName(qualIdent.toString() + ";");
- String className = getClassName(qualIdent.toString() + ";");
-
- if (typeArgs.isEmpty()) {
- parentType = factory.getClassReference(packageName, className);
- } else {
- IClassReference rawType = factory.getClassReference(packageName,
- className);
- SigParameterizedType parameterizedType = factory
- .getParameterizedType(null, rawType, typeArgs);
- parentType = parameterizedType;
- }
-
- ITypeReference typeToReturn = parentType;
-
-
- // if owner type is a parameterized type, the types are separated by '.'
- while (symbol == '.') {
- // Deal with Member Classes:
- scanSymbol();
- scanIdentifier();
- qualIdent.append("$").append(identifier);
- typeArgs = parseOptTypeArguments();
- ITypeReference memberType = null;
-
- packageName = getPackageName(qualIdent.toString() + ";");
- className = getClassName(qualIdent.toString() + ";");
-
- if (typeArgs.isEmpty()) {
- memberType = factory.getClassReference(packageName, className);
- } else {
- IClassReference rawType = factory.getClassReference(
- packageName, className);
- SigParameterizedType parameterizedType = factory
- .getParameterizedType(parentType, rawType, typeArgs);
- memberType = parameterizedType;
- }
- typeToReturn = memberType;
- }
-
- expect(';');
-
- return typeToReturn;
- }
-
- private List<ITypeReference> parseOptTypeArguments() {
- // OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">".
-
- List<ITypeReference> typeArgs = new ArrayList<ITypeReference>(8);
- if (symbol == '<') {
- scanSymbol();
-
- typeArgs.add(parseTypeArgument());
- while ((symbol != '>') && (symbol > 0)) {
- typeArgs.add(parseTypeArgument());
- }
- expect('>');
- }
- return typeArgs;
- }
-
- private ITypeReference parseTypeArgument() {
- // TypeArgument ::= (["+" | "-"] FieldTypeSignature) | "*".
- List<ITypeReference> extendsBound = new ArrayList<ITypeReference>(1);
- ITypeReference superBound = null;
- if (symbol == '*') {
- scanSymbol();
- extendsBound.add(factory.getClassReference("java.lang", "Object"));
- SigWildcardType wildcardType = factory.getWildcardType(superBound,
- extendsBound);
- return wildcardType;
- } else if (symbol == '+') {
- scanSymbol();
- extendsBound.add(parseFieldTypeSignature());
- SigWildcardType wildcardType = factory.getWildcardType(superBound,
- extendsBound);
- return wildcardType;
- } else if (symbol == '-') {
- scanSymbol();
- superBound = parseFieldTypeSignature();
- extendsBound.add(factory.getClassReference("java.lang", "Object"));
- SigWildcardType wildcardType = factory.getWildcardType(superBound,
- extendsBound);
- return wildcardType;
- } else {
- return parseFieldTypeSignature();
- }
- }
-
- private ITypeVariableReference parseTypeVariableSignature() {
- // TypeVariableSignature ::= "T" Ident ";".
- expect('T');
- scanIdentifier();
- expect(';');
-
- IGenericDeclaration declaration = genericDecl;
-
- if (!factory.containsTypeVariableDefinition(identifier, declaration)) {
- // since a field is not a generic declaration, i need to treat it
- // differently.
- // the generic declaration
- if (parseForField) {
- declaration = getDeclarationOfTypeVariable(identifier,
- (IClassDefinition) genericDecl);
- } else {
- declaration = getDeclarationOfTypeVariable(identifier,
- genericDecl.getDeclaringClass());
- }
- // just create type variable
- factory.getTypeVariable(identifier, declaration);
- }
-
- return factory.getTypeVariableReference(identifier, declaration);
- }
-
- private ITypeReference parseTypeSignature() {
- switch (symbol) {
- case 'B':
- scanSymbol();
- return SigPrimitiveType.BYTE_TYPE;
- case 'C':
- scanSymbol();
- return SigPrimitiveType.CHAR_TYPE;
- case 'D':
- scanSymbol();
- return SigPrimitiveType.DOUBLE_TYPE;
- case 'F':
- scanSymbol();
- return SigPrimitiveType.FLOAT_TYPE;
- case 'I':
- scanSymbol();
- return SigPrimitiveType.INT_TYPE;
- case 'J':
- scanSymbol();
- return SigPrimitiveType.LONG_TYPE;
- case 'S':
- scanSymbol();
- return SigPrimitiveType.SHORT_TYPE;
- case 'Z':
- scanSymbol();
- return SigPrimitiveType.BOOLEAN_TYPE;
- default:
- // Not an elementary type, but a FieldTypeSignature.
- return parseFieldTypeSignature();
- }
- }
-
- private void parseMethodTypeSignature() {
- // MethodTypeSignature ::= [FormalTypeParameters]
- // "(" {TypeSignature} ")" ReturnType {ThrowsSignature}.
-
- parseOptFormalTypeParameters();
-
- parameterTypes = new ArrayList<ITypeReference>(16);
- expect('(');
- while (symbol != ')' && (symbol > 0)) {
- parameterTypes.add(parseTypeSignature());
- }
- expect(')');
-
- returnType = parseReturnType();
-
- exceptionTypes = new ArrayList<ITypeReference>(8);
- while (symbol == '^') {
- scanSymbol();
-
- // ThrowsSignature ::= ("^" ClassTypeSignature) |
- // ("^" TypeVariableSignature).
- if (symbol == 'T') {
- exceptionTypes.add(parseTypeVariableSignature());
- } else {
- exceptionTypes.add(parseClassTypeSignature());
- }
- }
- }
-
- private ITypeReference parseReturnType() {
- // ReturnType ::= TypeSignature | "V".
- if (symbol != 'V') {
- return parseTypeSignature();
- } else {
- scanSymbol();
- return SigPrimitiveType.VOID_TYPE;
- }
- }
-
-
- //
- // Scanner:
- //
-
- private void scanSymbol() {
- if (!eof) {
- if (pos < buffer.length) {
- symbol = buffer[pos];
- pos++;
- } else {
- symbol = 0;
- eof = true;
- }
- } else {
- throw new GenericSignatureFormatError();
- }
- }
-
- private void expect(char c) {
- if (symbol == c) {
- scanSymbol();
- } else {
- throw new GenericSignatureFormatError();
- }
- }
-
- private boolean isStopSymbol(char ch) {
- switch (ch) {
- case ':':
- case '/':
- case ';':
- case '<':
- case '.':
- return true;
- }
- return false;
- }
-
- // PRE: symbol is the first char of the identifier.
- // POST: symbol = the next symbol AFTER the identifier.
- private void scanIdentifier() {
- if (!eof) {
- StringBuilder identBuf = new StringBuilder(32);
- if (!isStopSymbol(symbol)) {
- identBuf.append(symbol);
- do {
- char ch = buffer[pos];
- if ((ch >= 'a') && (ch <= 'z') || (ch >= 'A')
- && (ch <= 'Z') || !isStopSymbol(ch)) {
- identBuf.append(buffer[pos]);
- pos++;
- } else {
- identifier = identBuf.toString();
- scanSymbol();
- return;
- }
- } while (pos != buffer.length);
- identifier = identBuf.toString();
- symbol = 0;
- eof = true;
- } else {
- // Ident starts with incorrect char.
- symbol = 0;
- eof = true;
- throw new GenericSignatureFormatError();
- }
- } else {
- throw new GenericSignatureFormatError();
- }
- }
-}
diff --git a/tools/signature-tools/src/signature/converter/dex/IClassInitializer.java b/tools/signature-tools/src/signature/converter/dex/IClassInitializer.java
deleted file mode 100644
index 935ca49..0000000
--- a/tools/signature-tools/src/signature/converter/dex/IClassInitializer.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import signature.model.IClassDefinition;
-
-public interface IClassInitializer {
- IClassDefinition initializeClass(String packageName, String className);
-}
diff --git a/tools/signature-tools/src/signature/converter/doclet/DocletToSigConverter.java b/tools/signature-tools/src/signature/converter/doclet/DocletToSigConverter.java
deleted file mode 100644
index f9ebe77..0000000
--- a/tools/signature-tools/src/signature/converter/doclet/DocletToSigConverter.java
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.doclet;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-import java.util.Map.Entry;
-
-import signature.converter.Visibility;
-import signature.model.IAnnotation;
-import signature.model.IAnnotationElement;
-import signature.model.IAnnotationField;
-import signature.model.IApi;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IField;
-import signature.model.IGenericDeclaration;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigAnnotation;
-import signature.model.impl.SigAnnotationElement;
-import signature.model.impl.SigAnnotationField;
-import signature.model.impl.SigApi;
-import signature.model.impl.SigClassDefinition;
-import signature.model.impl.SigClassReference;
-import signature.model.impl.SigConstructor;
-import signature.model.impl.SigEnumConstant;
-import signature.model.impl.SigExecutableMember;
-import signature.model.impl.SigField;
-import signature.model.impl.SigMethod;
-import signature.model.impl.SigPackage;
-import signature.model.impl.SigParameter;
-import signature.model.impl.SigPrimitiveType;
-import signature.model.impl.SigTypeVariableDefinition;
-import signature.model.impl.SigTypeVariableReference;
-import signature.model.util.TypePool;
-
-import com.sun.javadoc.AnnotationDesc;
-import com.sun.javadoc.AnnotationTypeDoc;
-import com.sun.javadoc.AnnotationTypeElementDoc;
-import com.sun.javadoc.AnnotationValue;
-import com.sun.javadoc.ClassDoc;
-import com.sun.javadoc.ConstructorDoc;
-import com.sun.javadoc.ExecutableMemberDoc;
-import com.sun.javadoc.FieldDoc;
-import com.sun.javadoc.MethodDoc;
-import com.sun.javadoc.PackageDoc;
-import com.sun.javadoc.Parameter;
-import com.sun.javadoc.ParameterizedType;
-import com.sun.javadoc.ProgramElementDoc;
-import com.sun.javadoc.RootDoc;
-import com.sun.javadoc.Type;
-import com.sun.javadoc.TypeVariable;
-import com.sun.javadoc.WildcardType;
-import com.sun.javadoc.AnnotationDesc.ElementValuePair;
-
-public class DocletToSigConverter {
-
- TypePool pool;
- Set<String> packageNames;
-
- /**
- * Converts the signature information javadoc knows about into a
- * signature.model.ISources structure.
- */
- public IApi convertDocletRoot(String name, RootDoc root,
- Visibility visibility, Set<String> packageNames) {
- this.pool = new TypePool();
- this.packageNames = packageNames;
-
- Set<IPackage> packages = new HashSet<IPackage>();
-
- for (PackageDoc pack : root.specifiedPackages()) {
- assert packageNames.contains(pack.name());
- packages.add(convertPackage(pack));
- }
-
- SigApi sources = new SigApi(name, visibility);
- sources.setPackages(packages);
- return sources;
- }
-
- private IPackage convertPackage(PackageDoc packageDoc) {
- Set<IClassDefinition> classes = new HashSet<IClassDefinition>();
- for (ClassDoc clazz : packageDoc.allClasses()) {
- // classes.add((IClass)convertType(clazz));
- classes.add(convertClass(clazz));
- }
-
- SigPackage p = new SigPackage(packageDoc.name());
- p.setClasses(classes);
- p.setAnnotations(convertAnnotations(packageDoc.annotations()));
- return p;
- }
-
- private SigClassDefinition convertClass(ClassDoc classDoc) {
-
- SigClassDefinition c = pool.getClass(classDoc.containingPackage()
- .name(), classDoc.name());
- if (c.getKind() != Kind.UNINITIALIZED) return c;
-
- if (classDoc.isEnum())
- c.setKind(Kind.ENUM);
- else if (classDoc.isInterface())
- c.setKind(Kind.INTERFACE);
- else if (classDoc.isClass())
- c.setKind(Kind.CLASS);
- else if (classDoc.isAnnotationType()) c.setKind(Kind.ANNOTATION);
-
- if (!packageNames.contains(c.getPackageName())) {
- // no additional conversion for this class is necessary
- initializeClass(c);
- return c;
- }
-
- c.setModifiers(convertModifiers(classDoc.modifierSpecifier()));
- if (Kind.INTERFACE.equals(c.getKind())
- || Kind.ANNOTATION.equals(c.getKind())) {
- c.getModifiers().add(Modifier.ABSTRACT);
- }
-
- // superclass may be a class or a parameterized type (e.g. extends
- // List<String>),
- // may also be null if classDoc is an interface
- Type superclassType = classDoc.superclassType();
- if (superclassType != null) {
- c.setSuperClass(convertTypeReference(classDoc.superclassType()));
- } else {
- c.setSuperClass(null);
- }
-
- Set<ITypeReference> interfaces = new HashSet<ITypeReference>();
- for (Type interfaceType : classDoc.interfaceTypes()) {
- interfaces.add(convertTypeReference(interfaceType));
- }
- c.setInterfaces(interfaces);
-
- ClassDoc containingClass = classDoc.containingClass();
- if (containingClass != null)
- c.setDeclaringClass(convertClass(containingClass));
- else
- c.setDeclaringClass(null);
-
- Set<IClassDefinition> innerClasses = new HashSet<IClassDefinition>();
- for (ClassDoc innerClass : classDoc.innerClasses()) {
- innerClasses.add(convertClass(innerClass));
- }
- c.setInnerClasses(innerClasses);
-
- Set<IConstructor> constructors = new HashSet<IConstructor>();
- for (ConstructorDoc constructor : classDoc.constructors()) {
- constructors.add(convertConstructor(constructor));
- }
- c.setConstructors(constructors);
-
- Set<IMethod> methods = new HashSet<IMethod>();
- for (MethodDoc method : classDoc.methods()) {
- methods.add(convertMethod(method));
- }
- c.setMethods(methods);
-
- Set<IField> fields = new HashSet<IField>();
- for (FieldDoc field : classDoc.fields()) {
- fields.add(convertField(field));
- }
- c.setFields(fields);
-
- Set<IEnumConstant> enumConstants = new HashSet<IEnumConstant>();
- int ordinal = 0;
- for (FieldDoc enumConstant : classDoc.enumConstants()) {
- enumConstants.add(convertEnumConstant(enumConstant, ordinal++));
- }
- c.setEnumConstants(enumConstants);
-
- List<ITypeVariableDefinition> typeParameters =
- new LinkedList<ITypeVariableDefinition>();
- for (TypeVariable typeVariable : classDoc.typeParameters()) {
- typeParameters
- .add(((ITypeVariableReference) convertTypeReference(
- typeVariable)).getTypeVariableDefinition());
- }
- c.setTypeParameters(typeParameters);
-
- if (classDoc.isAnnotationType()) {
- Map<SigAnnotationField, AnnotationTypeElementDoc> annotationFieldAnnotations =
- new HashMap<SigAnnotationField, AnnotationTypeElementDoc>();
-
- // AnnotationTypeDoc annotationType =
- // classDoc.asAnnotationTypeDoc(); // bug in Doclet Implementation,
- // has been reported to sun
- AnnotationTypeDoc annotationType = (AnnotationTypeDoc) classDoc;
-
- Set<IAnnotationField> annotationFields =
- new HashSet<IAnnotationField>();
- for (AnnotationTypeElementDoc annotationElement : annotationType
- .elements()) {
- SigAnnotationField annotationField = new SigAnnotationField(
- annotationElement.name());
- annotationField.setModifiers(convertModifiers(annotationElement
- .modifierSpecifier()));
- annotationField.setType(convertTypeReference(annotationElement
- .returnType()));
- annotationField
- .setDefaultValue(convertAnnotationValue(
- annotationElement.defaultValue()));
-
- // the annotations on fields are set later because these
- // annotations may be of
- // the same type and may use fields which are not yet defined
- annotationFieldAnnotations.put(annotationField,
- annotationElement);
-
- annotationFields.add(annotationField);
- }
- c.setAnnotationFields(annotationFields);
-
- // set annotation field annotations
- for (Entry<SigAnnotationField, AnnotationTypeElementDoc> entry :
- annotationFieldAnnotations.entrySet()) {
- entry.getKey().setAnnotations(
- convertAnnotations(entry.getValue().annotations()));
- }
- } else { // no annotation type
- c.setAnnotationFields(null);
- }
-
- // set class annotations
- c.setAnnotations(convertAnnotations(classDoc.annotations()));
-
- return c;
-
- }
-
- private Object convertAnnotationValue(AnnotationValue annotationValue) {
- if (annotationValue == null) {
- return null;
- }
- Object value = annotationValue.value();
- if (value instanceof Type) {
- // Type contains primitive types as well, e.g. void.class
- return convertTypeReference((Type) value);
- } else if (value instanceof String) {
- return value;
- } else if (value instanceof Double || value instanceof Float
- || value instanceof Long || value instanceof Integer
- || value instanceof Short || value instanceof Byte
- || value instanceof Character || value instanceof Boolean) {
- return value;
- } else if (value instanceof FieldDoc) {
- FieldDoc field = (FieldDoc) value;
- String name = field.name();
- ITypeReference fieldType = convertTypeReference(field.type());
- IClassReference fieldClassRef = (IClassReference) fieldType;
- IClassDefinition fieldClass = fieldClassRef.getClassDefinition();
-
- assert fieldClass.getKind() == Kind.ENUM;
- Set<IEnumConstant> constants = fieldClass.getEnumConstants();
- for (IEnumConstant enumConstant : constants) {
- if (enumConstant.getName().equals(name)) value = enumConstant;
- }
- assert value instanceof IEnumConstant;
- return value;
- } else if (value instanceof AnnotationDesc) {
- return convertAnnotation((AnnotationDesc) value);
- } else if (value instanceof AnnotationValue) {
- return convertAnnotationValue((AnnotationValue) value);
- } else if (value instanceof AnnotationValue[]) {
- AnnotationValue[] arr = (AnnotationValue[]) value;
- int length = arr.length;
- Object[] annotationArray = new Object[length];
- for (int i = 0; i < length; i++) {
- annotationArray[i] = convertAnnotationValue(arr[i]);
- }
- return annotationArray;
- } else {
- throw new RuntimeException("not expected case");
- }
- }
-
- private ITypeReference convertArrayType(Type type) {
- assert type.asWildcardType() == null;
- assert type.asAnnotationTypeDoc() == null;
-
- ITypeReference baseType = null;
- if (type.asTypeVariable() != null) {
- baseType = convertTypeReference(type.asTypeVariable());
- } else if (type.asParameterizedType() != null) {
- baseType = convertTypeReference(type.asParameterizedType());
- } else if (type.asClassDoc() != null) {
- baseType = new SigClassReference(convertClass(type.asClassDoc()));
- } else if (type.isPrimitive()) {
- baseType = SigPrimitiveType.valueOfTypeName(type.typeName());
- } else {
- throw new RuntimeException(type.toString());
- }
-
- ITypeReference arrayType = baseType;
- int dimension = type.dimension().length() / 2;
- while (dimension > 0) {
- arrayType = pool.getArrayType(arrayType);
- dimension--;
- }
-
- return arrayType;
- }
-
- private SigTypeVariableDefinition currentTypeVariableDefinition = null;
-
- private ITypeReference convertTypeReference(Type type) {
- assert type != null;
-
- if (!"".equals(type.dimension())) {
- return convertArrayType(type);
- }
-
- ParameterizedType pType = type.asParameterizedType();
- if (pType != null) {
- ITypeReference ownerType = null;
- Type containingType = pType.containingType();
- if (containingType != null)
- ownerType = convertTypeReference(containingType);
- IClassReference rawType = new SigClassReference(convertClass(pType
- .asClassDoc()));
-
- List<ITypeReference> typeArguments =
- new LinkedList<ITypeReference>();
- for (Type typeArgument : pType.typeArguments()) {
- typeArguments.add(convertTypeReference(typeArgument));
- }
-
- if (typeArguments.size() > 0) {
- return pool.getParameterizedType(ownerType, rawType,
- typeArguments);
- } else {
- return rawType;
- }
- }
-
- TypeVariable tv = type.asTypeVariable();
- if (tv != null) {
- String name = tv.typeName();
-
- if (currentTypeVariableDefinition != null
- && name.equals(currentTypeVariableDefinition.getName()))
- return new SigTypeVariableReference(
- currentTypeVariableDefinition);
-
- IGenericDeclaration genericDeclaration = null;
- ProgramElementDoc programElement = tv.owner();
- if (programElement instanceof ClassDoc) {
- genericDeclaration = convertClass((ClassDoc) programElement);
- } else if (programElement instanceof MethodDoc
- && currentMethod.size() > 0) {
- genericDeclaration = currentMethod.peek();
- } else if (programElement instanceof ConstructorDoc
- && currentConstructor.size() > 0) {
- genericDeclaration = currentConstructor.peek();
- } else {
- throw new IllegalStateException("situation not expected");
- }
- SigTypeVariableDefinition typeVariable = pool.getTypeVariable(name,
- genericDeclaration);
-
- List<ITypeReference> upperBounds = new LinkedList<ITypeReference>();
- for (Type upperBound : tv.bounds()) {
- // we are converting a type variable declaration which is stored
- // in the
- // field currentTypeVariableDefinition
- assert currentTypeVariableDefinition == null;
- currentTypeVariableDefinition = typeVariable;
- upperBounds.add(convertTypeReference(upperBound));
- currentTypeVariableDefinition = null;
- }
- if (upperBounds.size() == 0) {
- // no explicit bounds, use java.lang.Object
- upperBounds.add(pool.getClassReference("java.lang", "Object"));
- }
- typeVariable.setUpperBounds(upperBounds);
-
- return new SigTypeVariableReference(typeVariable);
- }
-
- WildcardType wt = type.asWildcardType();
- if (wt != null) {
- ITypeReference lowerBound = null;
- for (Type superBound : wt.superBounds()) {
- lowerBound = convertTypeReference(superBound);
- }
-
- List<ITypeReference> upperBounds = new LinkedList<ITypeReference>();
- for (Type upperBound : wt.extendsBounds()) {
- upperBounds.add(convertTypeReference(upperBound));
- }
- if (upperBounds.size() == 0) {
- // no explicit bounds, use java.lang.Object
- upperBounds.add(pool.getClassReference("java.lang", "Object"));
- }
-
- return pool.getWildcardType(lowerBound, upperBounds);
- }
-
- ClassDoc c = type.asClassDoc();
- if (c != null) {
- return new SigClassReference(convertClass(c));
- }
-
- if (type.isPrimitive()) {
- return SigPrimitiveType.valueOfTypeName(type.typeName());
- }
-
- throw new IllegalStateException(type.toString());
- }
-
- private void convertExecutableMember(ExecutableMemberDoc member,
- SigExecutableMember m) {
- Set<Modifier> modifiers = convertModifiers(member.modifierSpecifier());
-
- // Doclet Bug: final values method is not considered as final
- if (member.containingClass().isEnum() && member.name().equals("values")
- && member.parameters().length == 0) {
- modifiers.add(Modifier.FINAL);
- }
-
- if (member.containingClass().isInterface()) {
- modifiers.add(Modifier.ABSTRACT);
- }
-
- m.setModifiers(modifiers);
- m.setAnnotations(convertAnnotations(member.annotations()));
- m.setDeclaringClass(convertClass(member.containingClass()));
-
- List<ITypeVariableDefinition> typeParameters =
- new LinkedList<ITypeVariableDefinition>();
- for (TypeVariable typeParameter : member.typeParameters()) {
- String name = typeParameter.typeName();
- IGenericDeclaration genericDeclaration = null;
- if (currentMethod.size() > 0)
- genericDeclaration = currentMethod.peek();
- else if (currentConstructor.size() > 0)
- genericDeclaration = currentConstructor.peek();
- else
- throw new RuntimeException();
- SigTypeVariableDefinition p = pool.getTypeVariable(name,
- genericDeclaration);
-
- List<ITypeReference> upperBounds = new LinkedList<ITypeReference>();
- for (Type u : typeParameter.bounds()) {
- upperBounds.add(convertTypeReference(u));
- }
- p.setUpperBounds(upperBounds);
- typeParameters.add(p);
- }
- m.setTypeParameters(typeParameters);
-
- List<IParameter> parameters = new LinkedList<IParameter>();
- for (Parameter parameter : member.parameters()) {
- SigParameter p = new SigParameter(convertTypeReference(parameter
- .type()));
- p.setAnnotations(convertAnnotations(parameter.annotations()));
- parameters.add(p);
- }
- m.setParameters(parameters);
-
- Set<ITypeReference> exceptions = new HashSet<ITypeReference>();
- for (Type exceptionType : member.thrownExceptionTypes()) {
- exceptions.add(convertTypeReference(exceptionType));
- }
- m.setExceptions(exceptions);
- }
-
- private Stack<SigMethod> currentMethod = new Stack<SigMethod>();
-
- private IMethod convertMethod(MethodDoc method) {
- SigMethod m = new SigMethod(method.name());
- currentMethod.push(m);
- convertExecutableMember(method, m);
- m.setReturnType(convertTypeReference(method.returnType()));
- currentMethod.pop();
- return m;
- }
-
- private Stack<SigConstructor> currentConstructor =
- new Stack<SigConstructor>();
-
- private IConstructor convertConstructor(ConstructorDoc constructor) {
- SigConstructor c = new SigConstructor(constructor.name());
- currentConstructor.push(c);
- convertExecutableMember(constructor, c);
- currentConstructor.pop();
- return c;
- }
-
- private IField convertField(FieldDoc field) {
- SigField f = new SigField(field.name());
- f.setAnnotations(convertAnnotations(field.annotations()));
- f.setModifiers(convertModifiers(field.modifierSpecifier()));
- f.setType(convertTypeReference(field.type()));
- return f;
- }
-
- private IEnumConstant convertEnumConstant(FieldDoc enumConstant,
- int ordinal) {
- SigEnumConstant ec = new SigEnumConstant(enumConstant.name());
- ec.setOrdinal(ordinal);
- ec.setAnnotations(convertAnnotations(enumConstant.annotations()));
- ec.setModifiers(convertModifiers(enumConstant.modifierSpecifier()));
- ec.setType(convertTypeReference(enumConstant.type()));
- return ec;
- }
-
- private Set<IAnnotation> convertAnnotations(
- AnnotationDesc[] annotationDescs) {
- Set<IAnnotation> annotations = new HashSet<IAnnotation>();
- for (AnnotationDesc annotationDesc : annotationDescs) {
- if (!annotationRetentionIsSource(annotationDesc))
- annotations.add(convertAnnotation(annotationDesc));
- }
- return annotations;
- }
-
- private boolean annotationRetentionIsSource(AnnotationDesc annotationDesc) {
- AnnotationTypeDoc type = annotationDesc.annotationType();
- AnnotationDesc[] annotations = type.annotations();
- for (AnnotationDesc d : annotations) {
- if ("java.lang.annotation.Retention".equals(d.annotationType()
- .qualifiedName())) {
- for (ElementValuePair value : d.elementValues()) {
- if ("value".equals(value.element().name())) {
- return "java.lang.annotation.RetentionPolicy.SOURCE"
- .equals(value.value().value().toString());
- }
- }
- }
- }
- // default retention policy is CLASS
- return false;
- }
-
- private IAnnotation convertAnnotation(AnnotationDesc annotationDesc) {
- SigAnnotation a = new SigAnnotation();
-
- IClassReference annotationType = (IClassReference) convertTypeReference(
- annotationDesc.annotationType());
- a.setType(annotationType);
-
- Set<IAnnotationElement> elements = new HashSet<IAnnotationElement>();
- for (AnnotationDesc.ElementValuePair pair : annotationDesc
- .elementValues()) {
- SigAnnotationElement element = new SigAnnotationElement();
- elements.add(element);
-
- element.setValue(convertAnnotationValue(pair.value()));
- String name = pair.element().name();
- for (IAnnotationField field : annotationType.getClassDefinition()
- .getAnnotationFields()) {
- if (field.getName().equals(name)) {
- element.setDeclaringField(field);
- }
- }
- }
- a.setElements(elements);
- return a;
- }
-
- private void initializeClass(SigClassDefinition c) {
- c.setAnnotationFields(null);
- c.setAnnotations(null);
- c.setConstructors(null);
- c.setDeclaringClass(null);
- c.setEnumConstants(null);
- c.setFields(null);
- c.setInnerClasses(null);
- c.setInterfaces(null);
- c.setMethods(null);
- c.setModifiers(null);
- c.setSuperClass(null);
- c.setTypeParameters(null);
- }
-
- private Set<Modifier> convertModifiers(int mod) {
- Set<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
- if (java.lang.reflect.Modifier.isAbstract(mod))
- modifiers.add(Modifier.ABSTRACT);
- if (java.lang.reflect.Modifier.isFinal(mod))
- modifiers.add(Modifier.FINAL);
- // if (java.lang.reflect.Modifier.isNative(mod))
- // modifiers.add(Modifier.NATIVE);
- if (java.lang.reflect.Modifier.isPrivate(mod))
- modifiers.add(Modifier.PRIVATE);
- if (java.lang.reflect.Modifier.isProtected(mod))
- modifiers.add(Modifier.PROTECTED);
- if (java.lang.reflect.Modifier.isPublic(mod))
- modifiers.add(Modifier.PUBLIC);
- if (java.lang.reflect.Modifier.isStatic(mod))
- modifiers.add(Modifier.STATIC);
- // if (java.lang.reflect.Modifier.isStrict(mod))
- // modifiers.add(Modifier.STRICT);
- // if (java.lang.reflect.Modifier.isSynchronized(mod))
- // modifiers.add(Modifier.SYNCHRONIZED);
- // if (java.lang.reflect.Modifier.isTransient(mod))
- // modifiers.add(Modifier.TRANSIENT);
- if (java.lang.reflect.Modifier.isVolatile(mod))
- modifiers.add(Modifier.VOLATILE);
-
- return modifiers;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/io/IApiDeltaExternalizer.java b/tools/signature-tools/src/signature/io/IApiDeltaExternalizer.java
deleted file mode 100644
index bf3cb8b..0000000
--- a/tools/signature-tools/src/signature/io/IApiDeltaExternalizer.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io;
-
-import java.io.IOException;
-
-import signature.compare.model.IApiDelta;
-
-public interface IApiDeltaExternalizer {
- void externalize(String location, IApiDelta delta) throws IOException;
-}
diff --git a/tools/signature-tools/src/signature/io/IApiExternalizer.java b/tools/signature-tools/src/signature/io/IApiExternalizer.java
deleted file mode 100644
index 3bbfbe5..0000000
--- a/tools/signature-tools/src/signature/io/IApiExternalizer.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io;
-
-import signature.model.IApi;
-
-import java.io.IOException;
-
-/**
- * This interface is used to write API definitions. Possible implementations of
- * this interface use Java serialization to store the API in binary form on the
- * disk. An alternative implementation can use ASCII files.
- */
-public interface IApiExternalizer {
- void externalizeApi(String loacation, IApi signature) throws IOException;
-}
diff --git a/tools/signature-tools/src/signature/io/IApiLoader.java b/tools/signature-tools/src/signature/io/IApiLoader.java
deleted file mode 100644
index a38fa1a..0000000
--- a/tools/signature-tools/src/signature/io/IApiLoader.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io;
-
-import java.io.IOException;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IApi;
-
-public interface IApiLoader {
- IApi loadApi(String name, Visibility visibility, Set<String> fileNames,
- Set<String> packageNames) throws IOException;
-}
diff --git a/tools/signature-tools/src/signature/io/html/ApiOverviewPage.java b/tools/signature-tools/src/signature/io/html/ApiOverviewPage.java
deleted file mode 100644
index d97c092..0000000
--- a/tools/signature-tools/src/signature/io/html/ApiOverviewPage.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import org.antlr.stringtemplate.StringTemplate;
-
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IPackageDelta;
-import signature.compare.model.impl.SigDelta;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public class ApiOverviewPage implements IEmitter {
-
- private final IApiDelta apiDelta;
-
- private List<IPackageDelta> removedPackages;
- private List<IPackageDelta> addedPackages;
- private List<IPackageDelta> changedPackages;
- private Map<String, String> commonInfos;
-
- public ApiOverviewPage(IApiDelta apiDelta,
- Map<String, String> commonInfos) {
- this.apiDelta = apiDelta;
- this.commonInfos = commonInfos;
- prepareData();
- }
-
- private void prepareData() {
- if (apiDelta.getPackageDeltas().isEmpty()) {
- commonInfos.put("no_delta", "no_delta");
- }
- removedPackages = new ArrayList<IPackageDelta>(SigDelta
- .getRemoved(apiDelta.getPackageDeltas()));
- Collections.sort(removedPackages, new PackageByNameComparator());
-
- addedPackages = new ArrayList<IPackageDelta>(SigDelta.getAdded(apiDelta
- .getPackageDeltas()));
- Collections.sort(addedPackages, new PackageByNameComparator());
-
- changedPackages = new ArrayList<IPackageDelta>(SigDelta
- .getChanged(apiDelta.getPackageDeltas()));
- Collections.sort(changedPackages, new PackageByNameComparator());
- }
-
- public void writeTo(StringBuilder b) {
- StringTemplate template = TemplateStore
- .getStringTemplate("ApiOverviewPage");
- template.setArgumentContext(commonInfos);
- template.setAttribute("removed_packages", removedPackages);
- template.setAttribute("added_packages", addedPackages);
- template.setAttribute("changed_packages", changedPackages);
- b.append(template.toString());
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/ClassByNameComparator.java b/tools/signature-tools/src/signature/io/html/ClassByNameComparator.java
deleted file mode 100644
index 8e23434..0000000
--- a/tools/signature-tools/src/signature/io/html/ClassByNameComparator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import signature.compare.model.IClassDefinitionDelta;
-
-import java.util.Comparator;
-
-public class ClassByNameComparator implements
- Comparator<IClassDefinitionDelta> {
-
- public int compare(IClassDefinitionDelta a, IClassDefinitionDelta b) {
- assert a.getType() == b.getType();
- if (a.getFrom() != null) {
- return a.getFrom().getName().compareTo(b.getFrom().getName());
- } else {
- return a.getTo().getName().compareTo(b.getTo().getName());
- }
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/ClassOverviewPage.java b/tools/signature-tools/src/signature/io/html/ClassOverviewPage.java
deleted file mode 100644
index 6951fb3..0000000
--- a/tools/signature-tools/src/signature/io/html/ClassOverviewPage.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Map;
-
-import org.antlr.stringtemplate.StringTemplate;
-
-import signature.compare.model.IAnnotationFieldDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IConstructorDelta;
-import signature.compare.model.IEnumConstantDelta;
-import signature.compare.model.IFieldDelta;
-import signature.compare.model.IMethodDelta;
-import signature.compare.model.impl.SigDelta;
-
-public class ClassOverviewPage implements IEmitter {
-
- private static final String PAGE = "ClassOverviewPage";
-
- private final IClassDefinitionDelta classDelta;
-
- private FieldByNameComparator<IFieldDelta> fieldComparator =
- new FieldByNameComparator<IFieldDelta>();
- private ArrayList<IFieldDelta> removedFields;
- private ArrayList<IFieldDelta> addedFields;
- private ArrayList<IFieldDelta> changedFields;
-
- private FieldByNameComparator<IAnnotationFieldDelta> annotationfieldComparator =
- new FieldByNameComparator<IAnnotationFieldDelta>();
- private ArrayList<IAnnotationFieldDelta> removedAnnotationFields;
- private ArrayList<IAnnotationFieldDelta> addedAnnotationFields;
- private ArrayList<IAnnotationFieldDelta> changedAnnotationFields;
-
- private FieldByNameComparator<IEnumConstantDelta> enumConstantComparator =
- new FieldByNameComparator<IEnumConstantDelta>();
- private ArrayList<IEnumConstantDelta> removedEnumConstants;
- private ArrayList<IEnumConstantDelta> addedEnumConstants;
- private ArrayList<IEnumConstantDelta> changedEnumConstants;
-
- private ExecutableMemberComparator constructorComparator =
- new ExecutableMemberComparator();
- private ArrayList<IConstructorDelta> removedConstructors;
- private ArrayList<IConstructorDelta> addedConstructors;
- private ArrayList<IConstructorDelta> changedConstructors;
-
- private ExecutableMemberComparator methodComparator =
- new ExecutableMemberComparator();
- private ArrayList<IMethodDelta> removedMethods;
- private ArrayList<IMethodDelta> addedMethods;
- private ArrayList<IMethodDelta> changedMethods;
-
- private final Map<String, String> commonInfos;
-
- public ClassOverviewPage(IClassDefinitionDelta classDelta,
- Map<String, String> commonInfos) {
- this.classDelta = classDelta;
- this.commonInfos = commonInfos;
- prepareData();
- }
-
- private void prepareData() {
- if (classDelta.getFieldDeltas() != null) {
- prepareFieldDeltas();
- }
- if (classDelta.getAnnotationFieldDeltas() != null) {
- prepareAnnotationFieldDeltas();
- }
- if (classDelta.getEnumConstantDeltas() != null) {
- prepareEnumConstantDeltas();
- }
- if (classDelta.getConstructorDeltas() != null) {
- prepareConstructorDeltas();
- }
- if (classDelta.getMethodDeltas() != null) {
- prepareMethodDeltas();
- }
- }
-
- private void prepareFieldDeltas() {
- removedFields = new ArrayList<IFieldDelta>(SigDelta
- .getRemoved(classDelta.getFieldDeltas()));
- Collections.sort(removedFields, fieldComparator);
-
- addedFields = new ArrayList<IFieldDelta>(SigDelta.getAdded(classDelta
- .getFieldDeltas()));
- Collections.sort(addedFields, fieldComparator);
-
- changedFields = new ArrayList<IFieldDelta>(SigDelta
- .getChanged(classDelta.getFieldDeltas()));
- Collections.sort(changedFields, fieldComparator);
- }
-
- private void prepareAnnotationFieldDeltas() {
- removedAnnotationFields = new ArrayList<IAnnotationFieldDelta>(SigDelta
- .getRemoved(classDelta.getAnnotationFieldDeltas()));
- Collections.sort(removedAnnotationFields, annotationfieldComparator);
-
- addedAnnotationFields = new ArrayList<IAnnotationFieldDelta>(SigDelta
- .getAdded(classDelta.getAnnotationFieldDeltas()));
- Collections.sort(addedAnnotationFields, annotationfieldComparator);
-
- changedAnnotationFields = new ArrayList<IAnnotationFieldDelta>(SigDelta
- .getChanged(classDelta.getAnnotationFieldDeltas()));
- Collections.sort(changedAnnotationFields, annotationfieldComparator);
- }
-
- private void prepareEnumConstantDeltas() {
- removedEnumConstants = new ArrayList<IEnumConstantDelta>(SigDelta
- .getRemoved(classDelta.getEnumConstantDeltas()));
- Collections.sort(removedEnumConstants, enumConstantComparator);
-
- addedEnumConstants = new ArrayList<IEnumConstantDelta>(SigDelta
- .getAdded(classDelta.getEnumConstantDeltas()));
- Collections.sort(addedEnumConstants, enumConstantComparator);
-
- changedEnumConstants = new ArrayList<IEnumConstantDelta>(SigDelta
- .getChanged(classDelta.getEnumConstantDeltas()));
- Collections.sort(changedEnumConstants, enumConstantComparator);
- }
-
- private void prepareConstructorDeltas() {
- removedConstructors = new ArrayList<IConstructorDelta>(SigDelta
- .getRemoved(classDelta.getConstructorDeltas()));
- Collections.sort(removedConstructors, constructorComparator);
-
- addedConstructors = new ArrayList<IConstructorDelta>(SigDelta
- .getAdded(classDelta.getConstructorDeltas()));
- Collections.sort(addedConstructors, constructorComparator);
-
- changedConstructors = new ArrayList<IConstructorDelta>(SigDelta
- .getChanged(classDelta.getConstructorDeltas()));
- Collections.sort(changedConstructors, constructorComparator);
- }
-
- private void prepareMethodDeltas() {
- removedMethods = new ArrayList<IMethodDelta>(SigDelta
- .getRemoved(classDelta.getMethodDeltas()));
- Collections.sort(removedMethods, methodComparator);
-
- addedMethods = new ArrayList<IMethodDelta>(SigDelta.getAdded(classDelta
- .getMethodDeltas()));
- Collections.sort(addedMethods, methodComparator);
-
- changedMethods = new ArrayList<IMethodDelta>(SigDelta
- .getChanged(classDelta.getMethodDeltas()));
- Collections.sort(changedMethods, methodComparator);
- }
-
- public void writeTo(StringBuilder b) {
- StringTemplate template = TemplateStore.getStringTemplate(PAGE);
-
- template.setAttribute("class_delta", classDelta);
- boolean annotationDelta = classDelta.getAnnotationDeltas() != null;
- boolean modifierDelta = classDelta.getModifierDeltas() != null;
- boolean typeVariableDelta = classDelta.getTypeVariableDeltas() != null;
- boolean superClassDelta = classDelta.getSuperClassDelta() != null;
- boolean interfaceDelta = classDelta.getInterfaceDeltas() != null;
- boolean hasSignatureDelta = annotationDelta || modifierDelta
- || typeVariableDelta || superClassDelta || interfaceDelta;
-
- template.setAttribute("has_class_signature_delta", hasSignatureDelta);
-
- template.setAttribute("removed_fields", removedFields);
- template.setAttribute("added_fields", addedFields);
- template.setAttribute("changed_fields", changedFields);
-
- template.setAttribute("removed_annotation_fields",
- removedAnnotationFields);
- template.setAttribute("added_annotation_fields", addedAnnotationFields);
- template.setAttribute("changed_annotation_fields",
- changedAnnotationFields);
-
- template.setAttribute("removed_enum_constants", removedEnumConstants);
- template.setAttribute("added_enum_constants", addedEnumConstants);
- template.setAttribute("changed_enum_constants", changedEnumConstants);
-
- template.setAttribute("removed_constructors", removedConstructors);
- template.setAttribute("added_constructors", addedConstructors);
- template.setAttribute("changed_constructors", changedConstructors);
-
- template.setAttribute("removed_methods", removedMethods);
- template.setAttribute("added_methods", addedMethods);
- template.setAttribute("changed_methods", changedMethods);
-
- template.setArgumentContext(commonInfos);
- b.append(template.toString());
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/ExecutableMemberComparator.java b/tools/signature-tools/src/signature/io/html/ExecutableMemberComparator.java
deleted file mode 100644
index e342342..0000000
--- a/tools/signature-tools/src/signature/io/html/ExecutableMemberComparator.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import signature.compare.model.IExecutableMemberDelta;
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IExecutableMember;
-import signature.model.IParameter;
-import signature.model.IParameterizedType;
-import signature.model.IPrimitiveType;
-import signature.model.ITypeDefinition;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-public class ExecutableMemberComparator implements
- Comparator<IExecutableMemberDelta<? extends IExecutableMember>> {
-
- public int compare(IExecutableMemberDelta<? extends IExecutableMember> a,
- IExecutableMemberDelta<? extends IExecutableMember> b) {
- assert a.getType() == b.getType();
- IExecutableMember aMember = null;
- IExecutableMember bMember = null;
-
- if (a.getFrom() != null) {
- aMember = a.getFrom();
- bMember = b.getFrom();
- } else {
- aMember = a.getTo();
- bMember = b.getTo();
- }
-
- int returnValue = aMember.getName().compareTo(bMember.getName());
- return returnValue != 0 ? returnValue : compareParameterLists(aMember
- .getParameters(), bMember.getParameters());
- }
-
- private int compareParameterLists(List<IParameter> a, List<IParameter> b) {
- if (a.size() != b.size()) {
- return a.size() - b.size();
- }
- Iterator<IParameter> aIt = a.iterator();
- Iterator<IParameter> bIt = b.iterator();
- int returnValue = 0;
- while (aIt.hasNext() && bIt.hasNext()) {
- returnValue += getTypeName(aIt.next().getType()).compareTo(
- getTypeName(bIt.next().getType()));
- }
- return returnValue;
- }
-
- private String getTypeName(ITypeReference type) {
- if (type instanceof IClassReference) {
- return getTypeName(((IClassReference) type).getClassDefinition());
- }
- if (type instanceof ITypeVariableReference) {
- return getTypeName(((ITypeVariableReference) type)
- .getTypeVariableDefinition());
- }
- if (type instanceof IParameterizedType) {
- return getTypeName(((IParameterizedType) type).getRawType());
- }
- if (type instanceof IArrayType) {
- return getTypeName(((IArrayType) type).getComponentType());
- }
- if (type instanceof IPrimitiveType) {
- return ((IPrimitiveType) type).getName();
- }
- return type.toString();
- }
-
- private String getTypeName(ITypeDefinition type) {
- if (type instanceof IClassDefinition) {
- return ((IClassDefinition) type).getName();
- }
- if (type instanceof ITypeVariableDefinition) {
- return ((ITypeVariableDefinition) type).getName();
- }
- return type.toString();
- }
-
-}
diff --git a/tools/signature-tools/src/signature/io/html/FieldByNameComparator.java b/tools/signature-tools/src/signature/io/html/FieldByNameComparator.java
deleted file mode 100644
index 9aaf1f8..0000000
--- a/tools/signature-tools/src/signature/io/html/FieldByNameComparator.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import java.util.Comparator;
-
-import signature.compare.model.IMemberDelta;
-import signature.model.IField;
-
-public class FieldByNameComparator<T extends IMemberDelta<?>> implements
- Comparator<T> {
-
- public int compare(T a, T b) {
- assert a.getType() == b.getType();
- IField aField = null;
- IField bField = null;
-
- // FIXME File javac or jdt bug.
- // Note: Casts are required by javac 1.5.0_16.
- if (a.getFrom() != null) {
- aField = (IField) a.getFrom();
- bField = (IField) b.getFrom();
- } else {
- aField = (IField) a.getTo();
- bField = (IField) b.getTo();
- }
- return aField.getName().compareTo(bField.getName());
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/HtmlDeltaExternalizer.java b/tools/signature-tools/src/signature/io/html/HtmlDeltaExternalizer.java
deleted file mode 100644
index 1ba5cba..0000000
--- a/tools/signature-tools/src/signature/io/html/HtmlDeltaExternalizer.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import org.antlr.stringtemplate.StringTemplate;
-
-import signature.Version;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IDelta;
-import signature.compare.model.IPackageDelta;
-import signature.compare.model.impl.SigDelta;
-import signature.io.IApiDeltaExternalizer;
-import signature.model.IClassDefinition;
-import signature.model.IPackage;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-public class HtmlDeltaExternalizer implements IApiDeltaExternalizer {
-
- private static final String OVERVIEW_PAGE_NAME = "changes.html";
- private static final String STYLE_SHEET_NAME = "styles.css";
- private static final String DELTA_FOLDER = "changes" + File.separator;
-
- public void externalize(String location, IApiDelta apiDelta)
- throws IOException {
- if (!location.endsWith(File.separator)) {
- location += File.separator;
- }
-
- File directory = new File(location);
- if (!directory.exists()) {
- directory.mkdirs();
- }
-
- copyStyleSheet(location);
-
- Map<String, String> commonInfos = new HashMap<String, String>();
- commonInfos.put("creation_time", DateFormat.getDateTimeInstance()
- .format(new Date()));
- commonInfos.put("from_desc", apiDelta.getFrom().getName());
- commonInfos.put("to_desc", apiDelta.getTo().getName());
-
- // write overview page
- StringBuilder content = new StringBuilder();
- ApiOverviewPage apiOverviewPage = new ApiOverviewPage(apiDelta,
- commonInfos);
- apiOverviewPage.writeTo(content);
- writeToFile(location + OVERVIEW_PAGE_NAME, content.toString());
-
- // write package overview
- Set<IPackageDelta> changedPackages = SigDelta.getChanged(apiDelta
- .getPackageDeltas());
- if (!changedPackages.isEmpty()) {
-
- File file = new File(location + DELTA_FOLDER);
- if (!file.exists()) {
- file.mkdir();
- }
-
- for (IPackageDelta packageDelta : changedPackages) {
- content = new StringBuilder();
- PackageOverviewPage packagePage = new PackageOverviewPage(
- packageDelta, commonInfos);
- packagePage.writeTo(content);
- IPackage aPackage = getAnElement(packageDelta);
- String packageOverviewFileName = location + DELTA_FOLDER
- + "pkg_" + aPackage.getName() + ".html";
- writeToFile(packageOverviewFileName, content.toString());
-
- // write class overviews
- for (IClassDefinitionDelta classDelta : packageDelta
- .getClassDeltas()) {
- content = new StringBuilder();
- ClassOverviewPage classPage = new ClassOverviewPage(
- classDelta, commonInfos);
- classPage.writeTo(content);
- IClassDefinition aClass = getAnElement(classDelta);
- String classOverviewFileName = location + DELTA_FOLDER
- + aPackage.getName() + "." + aClass.getName()
- + ".html";
- writeToFile(classOverviewFileName, content.toString());
- }
- }
- }
- // write class overview
- }
-
- private static <T> T getAnElement(IDelta<T> delta) {
- if (delta.getFrom() != null) {
- return delta.getFrom();
- } else {
- return delta.getTo();
- }
- }
-
- private void copyStyleSheet(String directory) throws IOException {
- StringTemplate template = TemplateStore.getStringTemplate("Styles");
- template.setAttribute("version", Version.VERSION);
- writeToFile(directory + STYLE_SHEET_NAME, template.toString());
- }
-
- private void writeToFile(String fileName, String content)
- throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream(fileName);
- fileOutputStream.write(content.getBytes());
- fileOutputStream.flush();
- fileOutputStream.close();
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/IEmitter.java b/tools/signature-tools/src/signature/io/html/IEmitter.java
deleted file mode 100644
index db73e66..0000000
--- a/tools/signature-tools/src/signature/io/html/IEmitter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-public interface IEmitter {
- void writeTo(StringBuilder b);
-}
diff --git a/tools/signature-tools/src/signature/io/html/PackageByNameComparator.java b/tools/signature-tools/src/signature/io/html/PackageByNameComparator.java
deleted file mode 100644
index 3bbff71..0000000
--- a/tools/signature-tools/src/signature/io/html/PackageByNameComparator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import signature.compare.model.IPackageDelta;
-import signature.model.IPackage;
-
-import java.util.Comparator;
-
-public class PackageByNameComparator implements Comparator<IPackageDelta> {
-
- public int compare(IPackageDelta a, IPackageDelta b) {
- assert a.getType() == b.getType();
- IPackage aPackage = null;
- IPackage bPackage = null;
-
- if (a.getFrom() != null) {
- aPackage = a.getFrom();
- bPackage = b.getFrom();
- } else {
- aPackage = a.getTo();
- bPackage = b.getTo();
- }
- return aPackage.getName().compareTo(bPackage.getName());
- }
-}
diff --git a/tools/signature-tools/src/signature/io/html/PackageOverviewPage.java b/tools/signature-tools/src/signature/io/html/PackageOverviewPage.java
deleted file mode 100644
index ccfe3cc..0000000
--- a/tools/signature-tools/src/signature/io/html/PackageOverviewPage.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import org.antlr.stringtemplate.StringTemplate;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IPackageDelta;
-import signature.compare.model.impl.SigDelta;
-
-public class PackageOverviewPage implements IEmitter {
-
- private static final String PACGE = "PackageOverviewPage";
-
- private final IPackageDelta delta;
-
- private List<IClassDefinitionDelta> removedClasses;
- private List<IClassDefinitionDelta> addedClasses;
- private List<IClassDefinitionDelta> changedClasses;
- private final Map<String, String> commonInfos;
-
-
- public PackageOverviewPage(IPackageDelta delta,
- Map<String, String> commonInfos) {
- this.delta = delta;
- this.commonInfos = commonInfos;
- prepareData();
- }
-
- private void prepareData() {
- removedClasses = new ArrayList<IClassDefinitionDelta>(SigDelta
- .getRemoved(delta.getClassDeltas()));
- Collections.sort(removedClasses, new ClassByNameComparator());
-
- addedClasses = new ArrayList<IClassDefinitionDelta>(SigDelta
- .getAdded(delta.getClassDeltas()));
- Collections.sort(addedClasses, new ClassByNameComparator());
-
- changedClasses = new ArrayList<IClassDefinitionDelta>(SigDelta
- .getChanged(delta.getClassDeltas()));
- Collections.sort(changedClasses, new ClassByNameComparator());
- }
-
- public void writeTo(StringBuilder b) {
- StringTemplate template = TemplateStore.getStringTemplate(PACGE);
- template.setArgumentContext(commonInfos);
- template.setAttribute("package_delta", delta);
- template.setAttribute("removed_classes", removedClasses);
- template.setAttribute("added_classes", addedClasses);
- template.setAttribute("changed_classes", changedClasses);
- b.append(template.toString());
- }
-
-
-
-}
diff --git a/tools/signature-tools/src/signature/io/html/TemplateStore.java b/tools/signature-tools/src/signature/io/html/TemplateStore.java
deleted file mode 100644
index a161bf7..0000000
--- a/tools/signature-tools/src/signature/io/html/TemplateStore.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.html;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.antlr.stringtemplate.StringTemplateGroup;
-import org.antlr.stringtemplate.language.DefaultTemplateLexer;
-
-public class TemplateStore {
-
- private static StringTemplateGroup group = initialize();
-
-
- private static StringTemplateGroup initialize() {
- InputStream modelStream = TemplateStore.class.getClassLoader()
- .getResourceAsStream("model/model.stg");
- InputStreamReader modelReader = new InputStreamReader(modelStream);
- StringTemplateGroup modelGroup = new StringTemplateGroup(modelReader,
- DefaultTemplateLexer.class);
-
- InputStream stream = TemplateStore.class.getClassLoader()
- .getResourceAsStream("delta/deltas.stg");
- InputStreamReader reader = new InputStreamReader(stream);
- StringTemplateGroup deltaGroup = new StringTemplateGroup(reader,
- DefaultTemplateLexer.class);
-
- StringTemplateGroup group = new StringTemplateGroup("signature", null,
- DefaultTemplateLexer.class);
- group.setSuperGroup(deltaGroup);
-
- deltaGroup.setSuperGroup(modelGroup);
- return group;
- }
-
- private TemplateStore() {/* no instances allowed */
- }
-
- public static StringTemplate getStringTemplate(String name) {
- return group.getInstanceOf(name);
- }
-}
diff --git a/tools/signature-tools/src/signature/io/impl/BinaryApi.java b/tools/signature-tools/src/signature/io/impl/BinaryApi.java
deleted file mode 100644
index f12cf6a7..0000000
--- a/tools/signature-tools/src/signature/io/impl/BinaryApi.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.impl;
-
-import signature.converter.Visibility;
-import signature.io.IApiExternalizer;
-import signature.io.IApiLoader;
-import signature.model.IApi;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.Set;
-
-public class BinaryApi implements IApiExternalizer, IApiLoader {
-
- public void externalizeApi(String fileName, IApi api) throws IOException {
-
- File directory = new File(fileName);
- if (!directory.exists()) {
- directory.mkdirs();
- }
-
- File file = new File(directory, getFileName(api));
- file.createNewFile();
-
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
- file));
- oos.writeObject(api);
-
- oos.flush();
- oos.close();
- }
-
- private String getFileName(IApi api) {
- return api.getName().replaceAll(" ", "_").concat(".sig");
- }
-
- public IApi loadApi(String name, Visibility visibility,
- Set<String> fileNames, Set<String> packageNames) throws
- IOException {
- System.err
- .println("Binary signature loader ignores visibility and " +
- "package names.");
- if (fileNames.size() != 1) {
- throw new IllegalArgumentException(
- "Only one file can be processed by the binary signature " +
- "loader.");
- }
- String fileName = fileNames.iterator().next();
- File file = new File(fileName);
- ObjectInputStream ois = new ObjectInputStream(
- new FileInputStream(file));
- IApi sig = null;
- try {
- sig = (IApi) ois.readObject();
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException(e);
- }
- if (name != null) {
- sig.setName(name);
- }
-
- ois.close();
- return sig;
- }
-}
diff --git a/tools/signature-tools/src/signature/io/impl/ToStringExternalizer.java b/tools/signature-tools/src/signature/io/impl/ToStringExternalizer.java
deleted file mode 100644
index 62615af..0000000
--- a/tools/signature-tools/src/signature/io/impl/ToStringExternalizer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.io.impl;
-
-import signature.compare.model.IApiDelta;
-import signature.io.IApiDeltaExternalizer;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-
-public class ToStringExternalizer implements IApiDeltaExternalizer {
-
- public void externalize(String location, IApiDelta delta)
- throws IOException {
-
- OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
- new FileOutputStream(location));
-
- if (delta == null) {
- outputStreamWriter.write("No delta found!");
- } else {
- outputStreamWriter.write(delta.toString());
- }
- outputStreamWriter.close();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/IAnnotatableElement.java b/tools/signature-tools/src/signature/model/IAnnotatableElement.java
deleted file mode 100644
index 53d6c38..0000000
--- a/tools/signature-tools/src/signature/model/IAnnotatableElement.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.Set;
-
-/**
- * Common interface for model elements which may be annotated. Annotations can
- * be attached to:
- * <ul>
- * <li>Classes (IClass), including annotations which are also classes
- * <li>Methods and Constructors (IExecutableMember)
- * <li>Fields (IField), including the annotation fields and enum constants
- * <li>Parameters (IParameter)
- * </ul>
- */
-public interface IAnnotatableElement {
-
- /**
- * Returns a set of annotations of a model element.
- *
- * @return a set of annotations of a model element
- */
- Set<IAnnotation> getAnnotations();
-}
diff --git a/tools/signature-tools/src/signature/model/IAnnotation.java b/tools/signature-tools/src/signature/model/IAnnotation.java
deleted file mode 100644
index c31689d..0000000
--- a/tools/signature-tools/src/signature/model/IAnnotation.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.Set;
-
-/**
- * {@code IAnnotation} models an <em>instance</em> of an annotation which is
- * attached to a program element. The definition of an annotation type is
- * modeled as an {@link IClassDefinition} with the {@link Kind#ANNOTATION}.
- */
-public interface IAnnotation {
- /**
- * Returns the annotation type of this annotation.
- *
- * @return the annotation type of this annotation
- */
- IClassReference getType();
-
- /**
- * Returns the elements declared in this annotation. The values which are
- * not declared are not contained in this list. Each element consists of its
- * name and its value.
- *
- * @return elements declared in this annotation
- */
- Set<IAnnotationElement> getElements();
-}
diff --git a/tools/signature-tools/src/signature/model/IAnnotationElement.java b/tools/signature-tools/src/signature/model/IAnnotationElement.java
deleted file mode 100644
index 5637fd6..0000000
--- a/tools/signature-tools/src/signature/model/IAnnotationElement.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IAnnotationElement} models an annotation element which consist of a
- * name and a value.
- */
-public interface IAnnotationElement {
- /**
- * Returns the value of this annotation element. The type of this value is
- * restricted to the possible value types for annotation elements.
- * <p>
- * The following types are possible:
- * <ul>
- * <li>a wrapper class for a primitive type
- * <li>String (for String values)
- * <li>IType (representing a class literal) FIXME Reference? Def?
- * <li>IEnumConstant (representing an enum constant)
- * <li>IAnnotation
- * </ul>
- * and (one-dimensional) arrays of the above types.
- *
- * @return the value of this annotation element
- */
- Object getValue();
-
- /**
- * Returns the corresponding annotation field declaration. This declaration
- * contains e.g. the name of this element, its type and its modifiers. The
- * declaration also contains the default value of this element which is
- * overwritten by this annotation element.
- *
- * @return the corresponding annotation field declaration
- */
- IAnnotationField getDeclaringField();
-
-}
diff --git a/tools/signature-tools/src/signature/model/IAnnotationField.java b/tools/signature-tools/src/signature/model/IAnnotationField.java
deleted file mode 100644
index c40707f..0000000
--- a/tools/signature-tools/src/signature/model/IAnnotationField.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IAnnotationField} models a field in a annotation definition. The
- * following example shows an annotation field <code>androField</code> of type
- * String and the default value "droid".
- *
- * <pre>
- *
- * @interface A { String androField() default "droid"; }
- *
- * </pre>
- */
-public interface IAnnotationField extends IField {
-
- /**
- * Returns the default value. If no default value is set then null is
- * returned.
- *
- * The type of the returned object is one of the following:
- * <ul>
- * <li>a wrapper class for a primitive type
- * <li>String (for String values)
- * <li>IType (representing a class literal)
- * <li>IEnumConstant (representing an enum constant)
- * <li>IAnnotation
- * </ul>
- * and (one-dimensional) arrays of the above types. If an array is returned,
- * then the type of the result is Object[]. The elements of this array are
- * of the above listed types.
- */
- Object getDefaultValue();
-}
diff --git a/tools/signature-tools/src/signature/model/IApi.java b/tools/signature-tools/src/signature/model/IApi.java
deleted file mode 100644
index de51938..0000000
--- a/tools/signature-tools/src/signature/model/IApi.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import signature.converter.Visibility;
-
-import java.util.Set;
-
-/**
- * {@code IApi} models the root of an api.
- */
-public interface IApi {
- /**
- * Returns the name of this api.
- *
- * @return the name of this api
- */
- String getName();
-
- /**
- * Sets the name of this api.
- *
- * @param name
- * the name of this api
- */
- void setName(String name);
-
- /**
- * Returns the set of packages which constitute this api.
- *
- * @return the set of packages which constitute this api
- */
- Set<IPackage> getPackages();
-
- /**
- * Returns the visibility of this api. The visibility describes which
- * elements are visible. Only elements with a visibility greater or equal
- * this visibility are contained in this api model.
- *
- * @return the visibility of this api
- * @see Visibility
- */
- Visibility getVisibility();
-}
diff --git a/tools/signature-tools/src/signature/model/IArrayType.java b/tools/signature-tools/src/signature/model/IArrayType.java
deleted file mode 100644
index bb63e67..0000000
--- a/tools/signature-tools/src/signature/model/IArrayType.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IArrayType} models an array type.
- */
-public interface IArrayType extends ITypeReference {
-
- /**
- * Returns the component type of this array type.
- *
- * @return component type of this array type
- */
- ITypeReference getComponentType();
-}
diff --git a/tools/signature-tools/src/signature/model/IClassDefinition.java b/tools/signature-tools/src/signature/model/IClassDefinition.java
deleted file mode 100644
index 1bd5401..0000000
--- a/tools/signature-tools/src/signature/model/IClassDefinition.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * {@code IClassDefinition} models a class definition. This is the model
- * equivalent to a class.
- */
-public interface IClassDefinition extends ITypeDefinition, IGenericDeclaration,
- IAnnotatableElement {
-
- /**
- * Returns the kind of this class definition.
- *
- * @return the kind of this class definition
- */
- Kind getKind();
-
- /**
- * Returns the name of this class definition.
- *
- * @return the name of this class definition
- */
- String getName();
-
- /**
- * Returns the '.' separated package name of this class.
- *
- * @return the '.' separated package name of this class
- */
- String getPackageName();
-
- /**
- * Returns a list containing each package fragment.
- * <p>
- * If {@link #getPackageName()} returns : "a.b.c" this method returns a list
- * containing the three elements "a", "b", "c".
- * <p>
- * Note: this method exists only for convenience in output templating.
- *
- * @return a list containing each package fragment
- */
- List<String> getPackageFragments();
-
- /**
- * Returns the qualified name of this class definition. The qualified name
- * is composed of {@link #getPackageName()} '.' {@link #getName()}
- *
- * @return the qualified name of this class definition
- */
- String getQualifiedName();
-
- /**
- * Returns the super class for this class definition. May return {@code
- * null} if this class definition does not have any superclass. This is the
- * case if the kind of this class definition is {@link Kind#INTERFACE} or
- * this class definition is {@link Object}.
- *
- * @return the super class for this class definition or {@code null}
- */
- ITypeReference getSuperClass();
-
- /**
- * Returns the declared interfaces this class definition implements . If no
- * interfaces are declared, an empty set is returned.
- *
- * @return the declared interfaces for this class definition
- */
- Set<ITypeReference> getInterfaces();
-
- /**
- * Returns the modifiers for this class definition.
- *
- * @return the modifiers for this class definition
- */
- Set<Modifier> getModifiers();
-
- /**
- * Returns all declared methods of this class definition.
- *
- * @return all declared methods of this class definition
- */
- Set<IMethod> getMethods();
-
- /**
- * Returns all declared constructors of this class definition.
- *
- * @return all declared constructors of this class definition
- */
- Set<IConstructor> getConstructors();
-
- /**
- * Returns all declared fields of this class definition.
- *
- * @return all declared fields of this class definition
- */
- Set<IField> getFields();
-
- /**
- * Returns all declared enumeration constant definitions of this class
- * definition. The returned set may only contain elements if the kind of
- * this class definition is {@link Kind#ENUM}.
- *
- * @return all declared enumeration constants of this class definition
- */
- Set<IEnumConstant> getEnumConstants();
-
- /**
- * Returns all declared annotation field definitions of this class
- * definition. The returned set may only contain elements if the kind of
- * this class definition is {@link Kind#ANNOTATION}.
- *
- * @return all declared annotation fields of this class definition
- */
- Set<IAnnotationField> getAnnotationFields();
-
- /**
- * Returns all classes which where defined in the lexical scope of this
- * class definition. Anonymous classes are never returned.
- *
- * @return all classes which where defined in the lexical scope of this
- * class definition
- */
- Set<IClassDefinition> getInnerClasses();
-}
diff --git a/tools/signature-tools/src/signature/model/IClassReference.java b/tools/signature-tools/src/signature/model/IClassReference.java
deleted file mode 100644
index bcb2c55..0000000
--- a/tools/signature-tools/src/signature/model/IClassReference.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IClassReference} models a reference to an {@link IClassDefinition}. If
- * the referenced {@link IClassDefinition} defines
- * {@link ITypeVariableDefinition}s, this reference can be seen as a raw type.
- */
-public interface IClassReference extends ITypeReference {
-
- /**
- * Returns the definition this class reference is referencing.
- *
- * @return the definition this class reference is referencing
- */
- IClassDefinition getClassDefinition();
-}
diff --git a/tools/signature-tools/src/signature/model/IConstructor.java b/tools/signature-tools/src/signature/model/IConstructor.java
deleted file mode 100644
index 29f5275..0000000
--- a/tools/signature-tools/src/signature/model/IConstructor.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IConstructor} models a constructor.
- */
-public interface IConstructor extends IExecutableMember {
-}
diff --git a/tools/signature-tools/src/signature/model/IEnumConstant.java b/tools/signature-tools/src/signature/model/IEnumConstant.java
deleted file mode 100644
index 681e62b..0000000
--- a/tools/signature-tools/src/signature/model/IEnumConstant.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IEnumConstant} models an enumeration constant.
- */
-public interface IEnumConstant extends IField {
-
- /**
- * Returns the ordinal of this enum constant.
- *
- * @return the ordinal of this enum constant.
- */
- int getOrdinal();
-}
diff --git a/tools/signature-tools/src/signature/model/IExecutableMember.java b/tools/signature-tools/src/signature/model/IExecutableMember.java
deleted file mode 100644
index ef7f7ba..0000000
--- a/tools/signature-tools/src/signature/model/IExecutableMember.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * {@code IExecutableMember} is the common super interface for methods an
- * constructors.
- */
-public interface IExecutableMember extends IGenericDeclaration,
- IAnnotatableElement {
-
- /**
- * Returns the name of this executable member.
- *
- * @return the name of this executable member
- */
- String getName();
-
- /**
- * Returns the parameters of this executable member.
- *
- * @return the parameters of this executable member
- */
- List<IParameter> getParameters();
-
- /**
- * Returns the declared exceptions of this executable member.
- *
- * @return the declared exceptions of this executable member
- */
- Set<ITypeReference> getExceptions();
-
- /**
- * Returns the modifiers of this executable member.
- *
- * @return the modifiers of this executable member
- */
- Set<Modifier> getModifiers();
-}
diff --git a/tools/signature-tools/src/signature/model/IField.java b/tools/signature-tools/src/signature/model/IField.java
deleted file mode 100644
index 3cf7593..0000000
--- a/tools/signature-tools/src/signature/model/IField.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.Set;
-
-/**
- * {@code IField} models a field.
- */
-public interface IField extends IAnnotatableElement {
-
- /**
- * Returns the name of this field.
- *
- * @return the name of this field
- */
- String getName();
-
- /**
- * Returns the type of this field.
- *
- * @return the type of this field
- */
- ITypeReference getType();
-
- /**
- * Returns the modifiers of this field.
- *
- * @return the modifiers of this field
- */
- Set<Modifier> getModifiers();
-}
diff --git a/tools/signature-tools/src/signature/model/IGenericDeclaration.java b/tools/signature-tools/src/signature/model/IGenericDeclaration.java
deleted file mode 100644
index d7f4683..0000000
--- a/tools/signature-tools/src/signature/model/IGenericDeclaration.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-
-/**
- * {@code IGenericDeclaration} is the common base interface for elements which
- * can define type variables.
- */
-public interface IGenericDeclaration {
-
- /**
- * Returns a list of all defined type variables on this generic declaration.
- *
- * @return a list of all defined type variables
- */
- List<ITypeVariableDefinition> getTypeParameters();
-
- /**
- * Returns the class definition which declares this element or {@code null}
- * if this declaration is a top level class definition.
- *
- * @return the class definition which declares this element or {@code null}
- */
- IClassDefinition getDeclaringClass();
-}
diff --git a/tools/signature-tools/src/signature/model/IMethod.java b/tools/signature-tools/src/signature/model/IMethod.java
deleted file mode 100644
index e205db1..0000000
--- a/tools/signature-tools/src/signature/model/IMethod.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import signature.model.impl.SigPrimitiveType;
-
-/**
- * {@code IMethod} models a method.
- */
-public interface IMethod extends IExecutableMember {
-
- /**
- * Returns the return type of this method.
- * <p>
- * If the declared return type is {@code void}
- * {@link SigPrimitiveType#VOID_TYPE} is returned.
- *
- * @return the return type of this method
- */
- ITypeReference getReturnType();
-}
diff --git a/tools/signature-tools/src/signature/model/IPackage.java b/tools/signature-tools/src/signature/model/IPackage.java
deleted file mode 100644
index 78b14ce..0000000
--- a/tools/signature-tools/src/signature/model/IPackage.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * {@code IPackage} models a package.
- */
-public interface IPackage extends IAnnotatableElement {
-
- /**
- * Returns the name of this package.
- *
- * @return the name of this package
- */
- String getName();
-
- /**
- * Returns a list containing each package fragment.
- * <p>
- * If {@link #getName()} returns : "a.b.c" this method returns a list
- * containing the three elements "a", "b", "c".
- * <p>
- * Note: this method exists only for convenience in output templating.
- *
- * @return a list containing each package fragment
- */
- List<String> getPackageFragments();
-
- /**
- * Returns all classes declared in this package, including ordinary classes,
- * interfaces, enum types and annotation types. Nested classes are returned
- * as well.
- *
- * @return all classes declared in this package
- */
- Set<IClassDefinition> getClasses();
-}
diff --git a/tools/signature-tools/src/signature/model/IParameter.java b/tools/signature-tools/src/signature/model/IParameter.java
deleted file mode 100644
index bd359d5..0000000
--- a/tools/signature-tools/src/signature/model/IParameter.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IParameter} models a parameter of an {@link IExecutableMember}.
- */
-public interface IParameter extends IAnnotatableElement {
-
- /**
- * Returns the type of this parameter.
- *
- * @return the type of this parameter
- */
- ITypeReference getType();
-}
diff --git a/tools/signature-tools/src/signature/model/IParameterizedType.java b/tools/signature-tools/src/signature/model/IParameterizedType.java
deleted file mode 100644
index 59f5692..0000000
--- a/tools/signature-tools/src/signature/model/IParameterizedType.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-
-/**
- * {@code IParameterizedType} models a parameterized type. A parameterized type
- * instantiates a generic class definition with actual type arguments.
- *
- * <pre>
- * IClassDefinition:
- * public class A<T> {}
- *
- * public class XXX {
- * IParameterizedType (raw type: A , type arguments: Number)
- * public A<Number> fields;
- * }
- * </pre>
- */
-public interface IParameterizedType extends ITypeReference {
-
- /**
- * Returns the actual type arguments of this parameterized type.
- *
- * @return the actual type arguments of this parameterized type
- */
- List<ITypeReference> getTypeArguments();
-
- /**
- * Returns the raw type of this parameterized type.
- *
- * @return the raw type of this parameterized type
- */
- IClassReference getRawType();
-
- /**
- * Returns the owner type of this parameterized type or {@code null}.
- *
- * <pre>
- * class Y<T> {
- * class Z<S> {
- * }
- *
- * Y<Integer>.Z<String> a;
- * }
- * </pre>
- */
- ITypeReference getOwnerType(); // A.B<String> -> A
-}
diff --git a/tools/signature-tools/src/signature/model/IPrimitiveType.java b/tools/signature-tools/src/signature/model/IPrimitiveType.java
deleted file mode 100644
index 917b96b..0000000
--- a/tools/signature-tools/src/signature/model/IPrimitiveType.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code IPrimitiveType} models a primitive type.
- */
-public interface IPrimitiveType extends ITypeReference {
-
- /**
- * Returns the name of this primitive type, i.e. one of the following
- * strings:
- * <ul>
- * <li><code>boolean</code>
- * <li><code>byte</code>
- * <li><code>char</code>
- * <li><code>short</code>
- * <li><code>int</code>
- * <li><code>float</code>
- * <li><code>double</code>
- * <li><code>void</code>
- * </ul>
- *
- * @return the name of this primitive type
- */
- public String getName();
-}
diff --git a/tools/signature-tools/src/signature/model/ITypeDefinition.java b/tools/signature-tools/src/signature/model/ITypeDefinition.java
deleted file mode 100644
index b182f21..0000000
--- a/tools/signature-tools/src/signature/model/ITypeDefinition.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code ITypeDefinition} is the common interface for type definitions. A type
- * definition is either an {@link ITypeVariableDefinition} or an
- * {@link IClassDefinition}.
- */
-public interface ITypeDefinition {
-}
diff --git a/tools/signature-tools/src/signature/model/ITypeReference.java b/tools/signature-tools/src/signature/model/ITypeReference.java
deleted file mode 100644
index f17f172..0000000
--- a/tools/signature-tools/src/signature/model/ITypeReference.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code ITypeReference} is the common interface for type references.
- */
-public interface ITypeReference {
-}
diff --git a/tools/signature-tools/src/signature/model/ITypeVariableDefinition.java b/tools/signature-tools/src/signature/model/ITypeVariableDefinition.java
deleted file mode 100644
index df0ead0..0000000
--- a/tools/signature-tools/src/signature/model/ITypeVariableDefinition.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-
-/**
- * {@code ITypeVariableDefinition} models a type variable definition.
- */
-public interface ITypeVariableDefinition extends ITypeDefinition {
-
- /**
- * Returns the upper bounds for this type variable as specified by the
- * extends clause. If no upper bounds are explicitly specified then
- * java.lang.Object is returned as upper bound.
- *
- * @return the upper bounds for this type variable
- */
- List<ITypeReference> getUpperBounds();
-
- /**
- * Returns the name of this type variable.
- *
- * @return the name of this type variable
- */
- String getName();
-
- /**
- * Returns the element on which this type variable is declared.
- *
- * @return the element on which this type variable is declared
- */
- IGenericDeclaration getGenericDeclaration();
-}
diff --git a/tools/signature-tools/src/signature/model/ITypeVariableReference.java b/tools/signature-tools/src/signature/model/ITypeVariableReference.java
deleted file mode 100644
index 64e0657..0000000
--- a/tools/signature-tools/src/signature/model/ITypeVariableReference.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * {@code ITypeVariableReference} models a reference to an
- * {@link ITypeVariableDefinition}.
- */
-public interface ITypeVariableReference extends ITypeReference {
-
- /**
- * Returns the definition this type variable reference is referencing.
- *
- * @return the definition this type variable reference is referencing
- */
- ITypeVariableDefinition getTypeVariableDefinition();
-}
diff --git a/tools/signature-tools/src/signature/model/IWildcardType.java b/tools/signature-tools/src/signature/model/IWildcardType.java
deleted file mode 100644
index 02a0d2d..0000000
--- a/tools/signature-tools/src/signature/model/IWildcardType.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.List;
-
-/**
- * {@code IWildcardType} models a wildcard type.
- */
-public interface IWildcardType extends ITypeReference {
-
- /**
- * Returns the upper bounds for this type variable as specified by the
- * extends clause. If no upper bounds are explicitly specified then
- * java.lang.Object is returned as upper bound.
- *
- * @return the upper bounds for this type variable
- */
- List<ITypeReference> getUpperBounds();
-
- /**
- * Returns the lower bounds for this type variable as specified by the super
- * clause. If no lower bounds are explicitly specified then null is returned
- * as lower bound.
- *
- * @return the lower bounds for this type variable
- */
- ITypeReference getLowerBound();
-
-}
diff --git a/tools/signature-tools/src/signature/model/Kind.java b/tools/signature-tools/src/signature/model/Kind.java
deleted file mode 100644
index 219e039..0000000
--- a/tools/signature-tools/src/signature/model/Kind.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-/**
- * Type of the modeled class.
- */
-public enum Kind {
- CLASS("class"), INTERFACE("interface"), ANNOTATION("@interface"), ENUM(
- "enum"), UNINITIALIZED("UNINITIALIZED");
-
- private final String name;
-
- Kind(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/Modifier.java b/tools/signature-tools/src/signature/model/Modifier.java
deleted file mode 100644
index 223e88f..0000000
--- a/tools/signature-tools/src/signature/model/Modifier.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model;
-
-import java.util.Set;
-
-/**
- * {@class Modifier} models a modifer.
- */
-public enum Modifier {
- PUBLIC("public"), PRIVATE("private"), PROTECTED("protected"), STATIC(
- "static"), FINAL("final"), SYNCHRONIZED("synchronized"), VOLATILE(
- "volatile"), TRANSIENT("transient"), NATIVE("native"), ABSTRACT(
- "abstract"), STRICT("strict");
-
- private final String printableName;
-
- private Modifier(String printableName) {
- this.printableName = printableName;
- }
-
- @Override
- public String toString() {
- return printableName;
- }
-
- public static String toString(Set<Modifier> modifiers) {
- StringBuilder s = new StringBuilder();
-
- for (Modifier modifier : values()) {
- if (modifiers.contains(modifier)) {
- s.append(modifier.printableName);
- s.append(" ");
- }
- }
-
- return s.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigAnnotatableElement.java b/tools/signature-tools/src/signature/model/impl/SigAnnotatableElement.java
deleted file mode 100644
index 53f021e..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigAnnotatableElement.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Set;
-
-import signature.model.IAnnotatableElement;
-import signature.model.IAnnotation;
-
-@SuppressWarnings("serial")
-public abstract class SigAnnotatableElement implements IAnnotatableElement,
- Serializable {
- private Set<IAnnotation> annotations;
-
- public SigAnnotatableElement() {
- annotations = Collections.emptySet();
- }
-
- public Set<IAnnotation> getAnnotations() {
- return annotations;
- }
-
- public void setAnnotations(Set<IAnnotation> annotations) {
- this.annotations = annotations;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- for (IAnnotation annotation : getAnnotations()) {
- builder.append(annotation);
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigAnnotation.java b/tools/signature-tools/src/signature/model/impl/SigAnnotation.java
deleted file mode 100644
index b7d0354..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigAnnotation.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IAnnotation;
-import signature.model.IAnnotationElement;
-import signature.model.IClassReference;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Set;
-
-@SuppressWarnings("serial")
-public class SigAnnotation implements IAnnotation, Serializable {
-
- private Set<IAnnotationElement> elements;
- private IClassReference type;
-
- public SigAnnotation() {
- elements = Collections.emptySet();
- }
-
- public IClassReference getType() {
- return type;
- }
-
- public void setType(IClassReference type) {
- this.type = type;
- }
-
- public Set<IAnnotationElement> getElements() {
- return elements;
- }
-
- public void setElements(Set<IAnnotationElement> elements) {
- this.elements = elements;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("@");
- builder.append(getType());
- if (!getElements().isEmpty()) {
- builder.append("{");
- for (IAnnotationElement element : getElements()) {
- builder.append("\n");
- builder.append(element.toString());
- }
- builder.append("}");
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigAnnotationElement.java b/tools/signature-tools/src/signature/model/impl/SigAnnotationElement.java
deleted file mode 100644
index 3d676a7..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigAnnotationElement.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.IAnnotationElement;
-import signature.model.IAnnotationField;
-
-@SuppressWarnings("serial")
-public class SigAnnotationElement implements IAnnotationElement, Serializable {
-
- private IAnnotationField declaringField;
- private Object value;
-
- public IAnnotationField getDeclaringField() {
- return declaringField;
- }
-
- public void setDeclaringField(IAnnotationField declaringField) {
- this.declaringField = declaringField;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(getDeclaringField().getName());
- builder.append(" = ");
- builder.append(getValue());
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigAnnotationField.java b/tools/signature-tools/src/signature/model/impl/SigAnnotationField.java
deleted file mode 100644
index 5dd6faf..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigAnnotationField.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.IAnnotationField;
-
-@SuppressWarnings("serial")
-public class SigAnnotationField extends SigField implements IAnnotationField,
- Serializable {
-
- private Object defaultValue = Uninitialized.unset();
-
- public SigAnnotationField(String name) {
- super(name);
- }
-
- public Object getDefaultValue() {
- return defaultValue;
- }
-
- public void setDefaultValue(Object defaultValue) {
- this.defaultValue = defaultValue;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigApi.java b/tools/signature-tools/src/signature/model/impl/SigApi.java
deleted file mode 100644
index b573f8f..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigApi.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IApi;
-import signature.model.IPackage;
-
-@SuppressWarnings("serial")
-public class SigApi implements IApi, Serializable {
-
- private Set<IPackage> packages = Uninitialized.unset();
- private String description;
- private Visibility visibility;
-
- public SigApi(String description, Visibility visibility) {
- this.description = description;
- this.visibility = visibility;
- }
-
- public String getName() {
- return description;
- }
-
- public void setName(String description) {
- this.description = description;
- }
-
- public Set<IPackage> getPackages() {
- return packages;
- }
-
- public void setPackages(Set<IPackage> packages) {
- this.packages = packages;
- }
-
- public Visibility getVisibility() {
- return visibility;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(getName());
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigArrayType.java b/tools/signature-tools/src/signature/model/impl/SigArrayType.java
deleted file mode 100644
index 3d20824e..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigArrayType.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.IArrayType;
-import signature.model.ITypeReference;
-
-@SuppressWarnings("serial")
-public class SigArrayType implements IArrayType, Serializable {
- private ITypeReference componentType;
-
- public SigArrayType(ITypeReference componentType) {
- this.componentType = componentType;
- }
-
- public ITypeReference getComponentType() {
- return componentType;
- }
-
- @Override
- public int hashCode() {
- return SigArrayType.hashCode(this);
- }
-
- public static int hashCode(IArrayType type) {
- return type.getComponentType().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigArrayType.equals(this, obj);
- }
-
- public static boolean equals(IArrayType thiz, Object that) {
- if (!(that instanceof IArrayType)) {
- return false;
- }
- IArrayType other = (IArrayType) that;
- return thiz.getComponentType().equals(other.getComponentType());
- }
-
- @Override
- public String toString() {
- return SigArrayType.toString(this);
- }
-
- public static String toString(IArrayType type) {
- StringBuilder builder = new StringBuilder();
- builder.append(type.getComponentType().toString());
- builder.append("[]");
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigClassDefinition.java b/tools/signature-tools/src/signature/model/impl/SigClassDefinition.java
deleted file mode 100644
index fe7c7ab..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigClassDefinition.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import signature.model.IAnnotationField;
-import signature.model.IClassDefinition;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IField;
-import signature.model.IMethod;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.util.ModelUtil;
-
-@SuppressWarnings("serial")
-public class SigClassDefinition extends SigAnnotatableElement implements
- IClassDefinition, Serializable {
-
- private String name;
- private Kind kind = Kind.UNINITIALIZED;
- private ITypeReference superClass = Uninitialized.unset();
- private Set<ITypeReference> interfaces = Uninitialized.unset();
- private Set<Modifier> modifiers = Uninitialized.unset();
- private Set<IMethod> methods = Uninitialized.unset();
- private Set<IConstructor> constructors = Uninitialized.unset();
- private Set<IClassDefinition> innerClasses = Uninitialized.unset();
- private Set<IAnnotationField> annotationFields = Uninitialized.unset();
- private Set<IField> fields = Uninitialized.unset();
- private Set<IEnumConstant> enumConstants = Uninitialized.unset();
- private IClassDefinition declaringClass = Uninitialized.unset();
- private List<ITypeVariableDefinition> typeParameters = Uninitialized
- .unset();
- private String packageName;
-
- public SigClassDefinition(String packageName, String name) {
- this.packageName = packageName;
- this.name = name;
- }
-
- public Kind getKind() {
- return kind;
- }
-
- public void setKind(Kind kind) {
- this.kind = kind;
- }
-
- public String getName() {
- return name;
- }
-
- public String getPackageName() {
- return packageName;
- }
-
- public List<String> getPackageFragments() {
- return Arrays.asList(packageName.split("\\."));
- }
-
- public String getQualifiedName() {
- return packageName + "." + name;
- }
-
- public Set<Modifier> getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(Set<Modifier> modifiers) {
- this.modifiers = modifiers;
- }
-
- public Set<IClassDefinition> getInnerClasses() {
- return innerClasses;
- }
-
- public void setInnerClasses(Set<IClassDefinition> innerClasses) {
- this.innerClasses = innerClasses;
- }
-
- public Set<ITypeReference> getInterfaces() {
- return interfaces;
- }
-
- public void setInterfaces(Set<ITypeReference> interfaces) {
- this.interfaces = interfaces;
- }
-
- public Set<IMethod> getMethods() {
- return methods;
- }
-
- public void setMethods(Set<IMethod> methods) {
- this.methods = methods;
- }
-
- public Set<IConstructor> getConstructors() {
- return constructors;
- }
-
- public void setConstructors(Set<IConstructor> constructors) {
- this.constructors = constructors;
- }
-
- public ITypeReference getSuperClass() {
- return superClass;
- }
-
- public void setSuperClass(ITypeReference superClass) {
- this.superClass = superClass;
- }
-
- public IClassDefinition getDeclaringClass() {
- return declaringClass;
- }
-
- public void setDeclaringClass(IClassDefinition declaringClass) {
- this.declaringClass = declaringClass;
- }
-
- public Set<IAnnotationField> getAnnotationFields() {
- return annotationFields;
- }
-
- public void setAnnotationFields(Set<IAnnotationField> annotationFields) {
- this.annotationFields = annotationFields;
- }
-
- public Set<IField> getFields() {
- return fields;
- }
-
- public void setFields(Set<IField> fields) {
- this.fields = fields;
- }
-
- public Set<IEnumConstant> getEnumConstants() {
- return enumConstants;
- }
-
- public void setEnumConstants(Set<IEnumConstant> enumConstants) {
- this.enumConstants = enumConstants;
- }
-
- public List<ITypeVariableDefinition> getTypeParameters() {
- return typeParameters;
- }
-
- public void setTypeParameters(
- List<ITypeVariableDefinition> typeParameters) {
- this.typeParameters = typeParameters;
- }
-
- @Override
- public int hashCode() {
- return SigClassDefinition.hashCode(this);
- }
-
- public static int hashCode(IClassDefinition definition) {
- // FIXME find out why name and packageName are null during
- // de-serialization some cases
- // replace the following lines with:
- // return definition.getQualifiedName().hashCode();
- final int prime = 31;
- int result = 1;
- result = prime
- + ((definition.getName() == null) ? 0 : definition.getName()
- .hashCode());
- result = prime
- * result
- + ((definition.getPackageName() == null) ? 0 : definition
- .getPackageName().hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigClassDefinition.equals(this, obj);
- }
-
- public static boolean equals(IClassDefinition thiz, Object obj) {
- if (thiz == obj) return true;
- if (obj instanceof IClassDefinition) {
- IClassDefinition that = (IClassDefinition) obj;
- return thiz.getName().equals(that.getName())
- && thiz.getPackageName().equals(that.getPackageName());
- }
- return false;
- }
-
- @Override
- public String toString() {
- return SigClassDefinition.toString(this);
- }
-
- public static String toString(IClassDefinition type) {
- StringBuilder builder = new StringBuilder();
- if (type.getAnnotations() != null && !type.getAnnotations().isEmpty()) {
- // FIXME print annotations builder.append(super.toString());
- builder.append("\n");
- }
- builder.append(type.getQualifiedName());
- if (type.getTypeParameters() != null
- && (!type.getTypeParameters().isEmpty())) {
- builder.append("<");
- ModelUtil.separate(type.getTypeParameters(), ", ");
- builder.append(">");
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigClassReference.java b/tools/signature-tools/src/signature/model/impl/SigClassReference.java
deleted file mode 100644
index d4336de..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigClassReference.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-
-import java.io.Serializable;
-
-@SuppressWarnings("serial")
-public class SigClassReference implements IClassReference, Serializable {
-
- private final IClassDefinition definition;
-
- public SigClassReference(IClassDefinition definition) {
- this.definition = definition;
- }
-
- public IClassDefinition getClassDefinition() {
- return definition;
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigClassReference.equals(this, obj);
- }
-
- public static boolean equals(IClassReference thiz, Object that) {
- if (that instanceof IClassReference) {
- return thiz.getClassDefinition().equals(
- ((IClassReference) that).getClassDefinition());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return SigClassReference.hashCode(this);
- }
-
- public static int hashCode(IClassReference thiz) {
- return thiz.getClassDefinition().hashCode();
- }
-
- @Override
- public String toString() {
- return SigClassReference.toString(this);
- }
-
- public static String toString(IClassReference thiz) {
- return "-> " + thiz.getClassDefinition().getQualifiedName();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigConstructor.java b/tools/signature-tools/src/signature/model/impl/SigConstructor.java
deleted file mode 100644
index 1da3026..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigConstructor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.IConstructor;
-import signature.model.Modifier;
-import signature.model.util.ModelUtil;
-
-@SuppressWarnings("serial")
-public class SigConstructor extends SigExecutableMember implements
- IConstructor, Serializable {
-
- public SigConstructor(String name) {
- super(name);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(super.toString());
- builder.append(" ");
- builder.append(Modifier.toString(getModifiers()));
- if (getTypeParameters() != null && !getTypeParameters().isEmpty()) {
- builder.append("<");
- builder.append(ModelUtil.separate(getTypeParameters(), ", "));
- builder.append("> ");
- }
- builder.append(getName());
- builder.append("(");
- builder.append(getParameters().isEmpty() ? "" : ModelUtil.separate(
- getParameters(), ", "));
- builder.append(")");
- if (getExceptions() != null && !getExceptions().isEmpty()) {
- builder.append(" throws ");
- builder.append(ModelUtil.separate(getExceptions(), " "));
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigEnumConstant.java b/tools/signature-tools/src/signature/model/impl/SigEnumConstant.java
deleted file mode 100644
index 2878988..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigEnumConstant.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IEnumConstant;
-
-@SuppressWarnings("serial")
-public class SigEnumConstant extends SigField implements IEnumConstant {
-
- private static final int UNKNOWN = -1;
-
- private int ordinal = UNKNOWN;
-
- public SigEnumConstant(String name) {
- super(name);
- }
-
- public int getOrdinal() {
- if (ordinal == UNKNOWN) {
- throw new UnsupportedOperationException();
- }
- return ordinal;
- }
-
- public void setOrdinal(int ordinal) {
- this.ordinal = ordinal;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigExecutableMember.java b/tools/signature-tools/src/signature/model/impl/SigExecutableMember.java
deleted file mode 100644
index 3203d59..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigExecutableMember.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IClassDefinition;
-import signature.model.IExecutableMember;
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.Modifier;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Set;
-
-@SuppressWarnings("serial")
-public abstract class SigExecutableMember extends SigAnnotatableElement
- implements IExecutableMember, Serializable {
-
- private String name;
- private List<IParameter> parameters = Uninitialized.unset();
- private Set<ITypeReference> exceptions = Uninitialized.unset();
- private Set<Modifier> modifiers = Uninitialized.unset();
- private List<ITypeVariableDefinition> typeParameters = Uninitialized
- .unset();
- private IClassDefinition declaringClass = Uninitialized.unset();
-
- public SigExecutableMember(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public List<IParameter> getParameters() {
- return parameters;
- }
-
- public void setParameters(List<IParameter> parameters) {
- this.parameters = parameters;
- }
-
- public Set<ITypeReference> getExceptions() {
- return exceptions;
- }
-
- public void setExceptions(Set<ITypeReference> exceptions) {
- this.exceptions = exceptions;
- }
-
- public Set<Modifier> getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(Set<Modifier> modifiers) {
- this.modifiers = modifiers;
- }
-
- public List<ITypeVariableDefinition> getTypeParameters() {
- return typeParameters;
- }
-
- public void setTypeParameters(
- List<ITypeVariableDefinition> typeParameters) {
- this.typeParameters = typeParameters;
- }
-
- public IClassDefinition getDeclaringClass() {
- return declaringClass;
- }
-
- public void setDeclaringClass(IClassDefinition declaringClass) {
- this.declaringClass = declaringClass;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigField.java b/tools/signature-tools/src/signature/model/impl/SigField.java
deleted file mode 100644
index e305566..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigField.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IField;
-import signature.model.ITypeReference;
-import signature.model.Modifier;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Set;
-
-@SuppressWarnings("serial")
-public class SigField extends SigAnnotatableElement implements IField,
- Serializable {
-
- private String name;
- private ITypeReference type = Uninitialized.unset();
- private Set<Modifier> modifiers = Uninitialized.unset();
-
- public SigField(String name) {
- this.name = name;
- modifiers = Collections.emptySet();
- }
-
- public String getName() {
- return name;
- }
-
- public Set<Modifier> getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(Set<Modifier> modifiers) {
- this.modifiers = modifiers;
- }
-
- public ITypeReference getType() {
- return type;
- }
-
- public void setType(ITypeReference type) {
- this.type = type;
- }
-
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- if (getAnnotations() != null && !getAnnotations().isEmpty()) {
- builder.append(super.toString());
- builder.append("\n");
- }
- builder.append(Modifier.toString(getModifiers()));
- builder.append(getType().toString());
- builder.append(" ");
- builder.append(getName());
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigMethod.java b/tools/signature-tools/src/signature/model/impl/SigMethod.java
deleted file mode 100644
index 489397f..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigMethod.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.IMethod;
-import signature.model.ITypeReference;
-import signature.model.Modifier;
-import signature.model.util.ModelUtil;
-
-@SuppressWarnings("serial")
-public class SigMethod extends SigExecutableMember implements IMethod,
- Serializable {
-
- private ITypeReference returnType = Uninitialized.unset();
-
- public SigMethod(String name) {
- super(name);
- }
-
-
- public ITypeReference getReturnType() {
- return returnType;
- }
-
- public void setReturnType(ITypeReference returnType) {
- this.returnType = returnType;
- }
-
- @Override
- public String toString() {
- return SigMethod.toString(this);
- }
-
- public static String toString(IMethod method) {
- StringBuilder builder = new StringBuilder();
- builder.append(Modifier.toString(method.getModifiers()));
- builder.append(method.getReturnType());
- builder.append(" ");
- if (method.getTypeParameters() != null
- && !method.getTypeParameters().isEmpty()) {
- builder.append("<");
- builder
- .append(ModelUtil
- .separate(method.getTypeParameters(), ", "));
- builder.append("> ");
- }
- builder.append(method.getName());
- builder.append("(");
- builder.append(method.getParameters().isEmpty() ? "" : ModelUtil
- .separate(method.getParameters(), ", "));
- builder.append(")");
- if (method.getExceptions() != null
- && !method.getExceptions().isEmpty()) {
- builder.append(" throws ");
- builder.append(ModelUtil.separate(method.getExceptions(), " "));
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigPackage.java b/tools/signature-tools/src/signature/model/impl/SigPackage.java
deleted file mode 100644
index 686917c..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigPackage.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IClassDefinition;
-import signature.model.IPackage;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-@SuppressWarnings("serial")
-public class SigPackage extends SigAnnotatableElement implements IPackage,
- Serializable {
-
- private String name;
- private Set<IClassDefinition> classes = Uninitialized.unset();
-
- public SigPackage(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public List<String> getPackageFragments() {
- return Arrays.asList(name.split("\\."));
- }
-
- public Set<IClassDefinition> getClasses() {
- return classes;
- }
-
- public void setClasses(Set<IClassDefinition> classes) {
- this.classes = classes;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("package: ");
- builder.append(getName());
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigParameter.java b/tools/signature-tools/src/signature/model/impl/SigParameter.java
deleted file mode 100644
index d9d3369..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigParameter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IParameter;
-import signature.model.ITypeReference;
-
-import java.io.Serializable;
-
-@SuppressWarnings("serial")
-public class SigParameter extends SigAnnotatableElement implements IParameter,
- Serializable {
-
- private ITypeReference type;
-
- public SigParameter(ITypeReference type) {
- this.type = type;
- }
-
- public ITypeReference getType() {
- return type;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(super.toString());
- builder.append(" ");
- builder.append(getType().toString());
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigParameterizedType.java b/tools/signature-tools/src/signature/model/impl/SigParameterizedType.java
deleted file mode 100644
index d726135..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigParameterizedType.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IClassReference;
-import signature.model.IParameterizedType;
-import signature.model.ITypeReference;
-import signature.model.util.ModelUtil;
-
-import java.io.Serializable;
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class SigParameterizedType implements IParameterizedType, Serializable {
-
- private ITypeReference ownerType;
- private IClassReference rawType;
- private List<ITypeReference> typeArguments;
-
- public SigParameterizedType(ITypeReference ownerType,
- IClassReference rawType, List<ITypeReference> typeArguments) {
- this.ownerType = ownerType;
- this.rawType = rawType;
- this.typeArguments = typeArguments;
- }
-
- public ITypeReference getOwnerType() {
- ITypeReference returnValue = ownerType;
- if (returnValue == null) {
- if (rawType.getClassDefinition().getDeclaringClass() != null) {
- returnValue = new SigClassReference(rawType
- .getClassDefinition().getDeclaringClass());
- }
- }
- return returnValue;
- }
-
- public IClassReference getRawType() {
- return rawType;
- }
-
- public List<ITypeReference> getTypeArguments() {
- return typeArguments;
- }
-
- @Override
- public int hashCode() {
- return hashCode(this);
- }
-
- public static int hashCode(IParameterizedType type) {
- final int prime = 31;
- int result = 1;
- result = prime * type.getRawType().hashCode();
- result = prime * result + type.getTypeArguments().hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- return equals(this, obj);
- }
-
- public static boolean equals(IParameterizedType thiz, Object that) {
- if (!(that instanceof IParameterizedType)) {
- return false;
- }
- IParameterizedType other = (IParameterizedType) that;
- if (thiz.getOwnerType() == null) {
- if (other.getOwnerType() != null) {
- return false;
- }
- } else if (Uninitialized.isInitialized(thiz.getOwnerType())) {
- if (!Uninitialized.isInitialized(other.getOwnerType())) {
- return false;
- }
- } else if (!thiz.getOwnerType().equals(other.getOwnerType())) {
- return false;
- }
- if (!thiz.getRawType().equals(other.getRawType())) {
- return false;
- }
- if (!thiz.getTypeArguments().equals(other.getTypeArguments())) {
- return false;
- }
- return true;
- }
-
-
- @Override
- public String toString() {
- return SigParameterizedType.toString(this);
- }
-
- public static String toString(IParameterizedType type) {
- StringBuilder builder = new StringBuilder();
- if (type.getOwnerType() != null) {
- builder.append(type.getOwnerType().toString());
- builder.append("::");
- }
- builder.append(type.getRawType());
- builder.append("<");
- builder.append(ModelUtil.separate(type.getTypeArguments(), ", "));
- builder.append(">");
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigPrimitiveType.java b/tools/signature-tools/src/signature/model/impl/SigPrimitiveType.java
deleted file mode 100644
index 2786169..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigPrimitiveType.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IPrimitiveType;
-
-public enum SigPrimitiveType implements IPrimitiveType {
- VOID_TYPE("void"), BOOLEAN_TYPE("boolean"), BYTE_TYPE("byte"), CHAR_TYPE(
- "char"), SHORT_TYPE("short"), INT_TYPE("int"), LONG_TYPE("long"),
- FLOAT_TYPE("float"), DOUBLE_TYPE("double");
-
- private String name;
-
- private SigPrimitiveType(String name) {
- this.name = name;
- }
-
- public static SigPrimitiveType valueOfTypeName(String name) {
- for (SigPrimitiveType primitive : values()) {
- if (primitive.name.equals(name)) {
- return primitive;
- }
- }
- throw new IllegalArgumentException(name + " is not a primitive type");
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigTypeVariableDefinition.java b/tools/signature-tools/src/signature/model/impl/SigTypeVariableDefinition.java
deleted file mode 100644
index e0f918e..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigTypeVariableDefinition.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.IGenericDeclaration;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.util.ModelUtil;
-
-import java.io.Serializable;
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class SigTypeVariableDefinition implements ITypeVariableDefinition,
- Serializable {
-
- private String name;
- private IGenericDeclaration genericDeclaration;
- private List<ITypeReference> upperBounds = Uninitialized.unset();
-
- public SigTypeVariableDefinition(String name,
- IGenericDeclaration genericDeclaration) {
- this.name = name;
- this.genericDeclaration = genericDeclaration;
- }
-
- public String getName() {
- return name;
- }
-
- public IGenericDeclaration getGenericDeclaration() {
- return genericDeclaration;
- }
-
- public List<ITypeReference> getUpperBounds() {
- return upperBounds;
- }
-
- public void setUpperBounds(List<ITypeReference> upperBounds) {
- this.upperBounds = upperBounds;
- }
-
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(name);
- if (getUpperBounds().size() != 1) {
- builder.append(ModelUtil.separate(getUpperBounds(), ", "));
- } else {
- if (!ModelUtil.isJavaLangObject(getUpperBounds().get(0))) {
- builder.append(getUpperBounds().get(0));
- }
- }
- return builder.toString();
- }
-
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigTypeVariableReference.java b/tools/signature-tools/src/signature/model/impl/SigTypeVariableReference.java
deleted file mode 100644
index 6bd2593..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigTypeVariableReference.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.io.Serializable;
-
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-
-@SuppressWarnings("serial")
-public class SigTypeVariableReference implements ITypeVariableReference,
- Serializable {
-
- private ITypeVariableDefinition definition;
-
- public SigTypeVariableReference(ITypeVariableDefinition definition) {
- this.definition = definition;
- }
-
- public ITypeVariableDefinition getTypeVariableDefinition() {
- return definition;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (getClass() == obj.getClass()) {
- return getTypeVariableDefinition().equals(
- ((ITypeVariableReference) obj).getTypeVariableDefinition());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return getTypeVariableDefinition().hashCode();
- }
-
- @Override
- public String toString() {
- return getTypeVariableDefinition().getName();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/SigWildcardType.java b/tools/signature-tools/src/signature/model/impl/SigWildcardType.java
deleted file mode 100644
index c24ac23..0000000
--- a/tools/signature-tools/src/signature/model/impl/SigWildcardType.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import signature.model.ITypeReference;
-import signature.model.IWildcardType;
-
-import java.io.Serializable;
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class SigWildcardType implements IWildcardType, Serializable {
-
- private ITypeReference lowerBound;
- private List<ITypeReference> upperBounds;
-
- public SigWildcardType(ITypeReference lowerBound,
- List<ITypeReference> upperBounds) {
- this.lowerBound = lowerBound;
- this.upperBounds = upperBounds;
- }
-
- public ITypeReference getLowerBound() {
- return lowerBound;
- }
-
- public List<ITypeReference> getUpperBounds() {
- return upperBounds;
- }
-
- @Override
- public int hashCode() {
- return SigWildcardType.hashCode(this);
- }
-
- public static int hashCode(IWildcardType type) {
- final int prime = 31;
- int result = 1;
- result = prime
- + ((type.getLowerBound() == null) ? 0 : type.getLowerBound()
- .hashCode());
- result = prime * result + type.getUpperBounds().hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- return SigWildcardType.equals(this, obj);
- }
-
- public static boolean equals(IWildcardType thiz, Object obj) {
- if (thiz == obj) return true;
- if (obj == null) return false;
- if (!(obj instanceof IWildcardType)) return false;
- IWildcardType that = (IWildcardType) obj;
- if (thiz.getLowerBound() == null) {
- if (that.getLowerBound() != null) return false;
- } else if (!thiz.getLowerBound().equals(that.getLowerBound()))
- return false;
- if (!thiz.getUpperBounds().equals(that.getUpperBounds())) return false;
- return true;
- }
-
-
- @Override
- public String toString() {
- return SigWildcardType.toString(this);
- }
-
- public static String toString(IWildcardType thiz) {
- StringBuilder builder = new StringBuilder();
- builder.append("?");
- if (thiz.getLowerBound() != null) {
- builder.append(" ");
- builder.append(" super ");
- builder.append(thiz.getLowerBound());
- }
- if (!thiz.getUpperBounds().isEmpty()) {
- builder.append(" extends ");
- builder.append(thiz.getUpperBounds());
- }
- return builder.toString();
- }
-}
diff --git a/tools/signature-tools/src/signature/model/impl/Uninitialized.java b/tools/signature-tools/src/signature/model/impl/Uninitialized.java
deleted file mode 100644
index cc88479..0000000
--- a/tools/signature-tools/src/signature/model/impl/Uninitialized.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.impl;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.List;
-import java.util.Set;
-
-import signature.model.IAnnotationField;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IPackage;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.Kind;
-
-/**
- *
- */
-public class Uninitialized {
-
- private static final Object UNINITIALIZED;
-
- static {
- UNINITIALIZED = Proxy.newProxyInstance(Uninitialized.class
- .getClassLoader(), new Class[] {
- ITypeReference.class, IPackage.class, IClassDefinition.class,
- IClassReference.class, ITypeVariableReference.class,
- ITypeVariableDefinition.class, IAnnotationField.class,
- Set.class, List.class}, new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- if (method.getName().equals("toString")) {
- return "Uninitialized";
- }
-
- throw new UnsupportedOperationException();
- }
- });
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T unset() {
- return (T) UNINITIALIZED;
- }
-
- public static boolean isInitialized(Object o) {
- return o != UNINITIALIZED && o != Kind.UNINITIALIZED;
- }
-}
diff --git a/tools/signature-tools/src/signature/model/util/ITypeFactory.java b/tools/signature-tools/src/signature/model/util/ITypeFactory.java
deleted file mode 100644
index af3e3a9..0000000
--- a/tools/signature-tools/src/signature/model/util/ITypeFactory.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.util;
-
-import signature.model.IClassReference;
-import signature.model.IGenericDeclaration;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableReference;
-import signature.model.impl.SigArrayType;
-import signature.model.impl.SigClassDefinition;
-import signature.model.impl.SigParameterizedType;
-import signature.model.impl.SigTypeVariableDefinition;
-import signature.model.impl.SigWildcardType;
-
-import java.util.List;
-
-public interface ITypeFactory {
-
- public static final String JAVA_LANG_OBJECT = "java.lang.Object";
-
- /**
- * Returns the existing type or creates a new one.<br>
- * Format: java.lang.Object
- */
- public SigClassDefinition getClass(String packageName, String className);
-
- public IClassReference getClassReference(String packageName,
- String className);
-
- /**
- * Returns the existing array type or creates a new one.
- *
- * @param componentType
- * the component type of the array
- * @return the array type
- */
- public SigArrayType getArrayType(ITypeReference componentType);
-
- /**
- * Returns the existing parameterized type or creates a new one.
- *
- * @param ownerType
- * the owner of the parameterized type
- * @param rawType
- * the type which is parameterized
- * @param typeArguments
- * the type arguments
- * @return the parameterized type
- */
- public SigParameterizedType getParameterizedType(ITypeReference ownerType,
- IClassReference rawType, List<ITypeReference> typeArguments);
-
-
- public boolean containsTypeVariableDefinition(String name,
- IGenericDeclaration genericDeclaration);
-
- /**
- * Returns the existing type variable or creates a new one.
- *
- * @param genericDeclaration
- * the declaration site of the variable
- * @param name
- * the name of the type variable
- * @return the type variable
- */
- public SigTypeVariableDefinition getTypeVariable(String name,
- IGenericDeclaration genericDeclaration);
-
- public ITypeVariableReference getTypeVariableReference(String name,
- IGenericDeclaration genericDeclaration);
-
- /**
- * Returns the existing wildcard type or creates a new one. Wildcard types
- * are equal if they have the same lower bound and have the same upper
- * bounds. The order of the upper bounds is irrelevant except for the first
- * element. <br>
- * Note: This does not mean that two values with equal wildcard type can be
- * assigned to each other!
- *
- * @param lowerBound
- * the lower bound
- * @param upperBounds
- * the upper bounds
- * @return the wildcard type
- */
- public SigWildcardType getWildcardType(ITypeReference lowerBound,
- List<ITypeReference> upperBounds);
-
-}
diff --git a/tools/signature-tools/src/signature/model/util/ModelUtil.java b/tools/signature-tools/src/signature/model/util/ModelUtil.java
deleted file mode 100644
index f66fd2c..0000000
--- a/tools/signature-tools/src/signature/model/util/ModelUtil.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.util;
-
-import signature.model.IAnnotatableElement;
-import signature.model.IAnnotation;
-import signature.model.IAnnotationElement;
-import signature.model.IAnnotationField;
-import signature.model.IApi;
-import signature.model.IClassDefinition;
-import signature.model.IField;
-import signature.model.IPackage;
-import signature.model.ITypeReference;
-
-import java.util.Collection;
-
-public class ModelUtil {
- private ModelUtil() {
- }
-
- /**
- * Returns the IClass for the given className.<br>
- * Format: a.b.C
- *
- * @param qualifiedClassName
- * the fully qualified class name
- * @return the IClass instance or null;
- */
- public static IClassDefinition getClass(IPackage aPackage,
- String qualifiedClassName) {
- for (IClassDefinition clazz : aPackage.getClasses()) {
- if (qualifiedClassName.equals(clazz.getName())) {
- return clazz;
- }
- }
- return null;
- }
-
- public static IAnnotation getAnnotation(IAnnotatableElement element,
- String qualifiedTypeName) {
- for (IAnnotation annotation : element.getAnnotations()) {
- if (qualifiedTypeName.equals(annotation.getType()
- .getClassDefinition().getQualifiedName())) {
- return annotation;
- }
- }
- return null;
- }
-
- public static IAnnotationElement getAnnotationElement(
- IAnnotation annotation, String elementName) {
- for (IAnnotationElement element : annotation.getElements()) {
- if (elementName.equals(element.getDeclaringField().getName())) {
- return element;
- }
- }
- return null;
- }
-
- public static IField getField(IClassDefinition clazz, String fieldName) {
- for (IField field : clazz.getFields()) {
- if (fieldName.equals(field.getName())) {
- return field;
- }
- }
- return null;
- }
-
- public static IAnnotationField getAnnotationField(
- IClassDefinition annotation, String fieldName) {
- for (IAnnotationField field : annotation.getAnnotationFields()) {
- if (fieldName.equals(field.getName())) {
- return field;
- }
- }
- return null;
- }
-
- /**
- * Returns the IPackage for the given className.<br>
- * Format: a.b
- *
- * @param api
- * the api
- * @param packageName
- * the name of the package
- * @return the IClass instance or null;
- */
- public static IPackage getPackage(IApi api, String packageName) {
- for (IPackage aPackage : api.getPackages()) {
- if (packageName.equals(aPackage.getName())) {
- return aPackage;
- }
- }
- return null;
- }
-
- /**
- * "a.b.c.A;" -> "a.b.c" "A" -> "" empty string
- *
- * @param classIdentifier
- * @return the package name
- */
- public static String getPackageName(String classIdentifier) {
- int lastIndexOfSlash = classIdentifier.lastIndexOf('.');
- String packageName = null;
- if (lastIndexOfSlash == -1) {
- packageName = "";
- } else {
- packageName = classIdentifier.substring(0, lastIndexOfSlash);
- }
- return packageName;
- }
-
- /**
- * "a.b.c.A;" -> "A" "A" -> "A"
- *
- * @param classIdentifier
- * fully qualified class name
- * @return the class name
- */
- public static String getClassName(String classIdentifier) {
- int lastIndexOfDot = classIdentifier.lastIndexOf('.');
- String className = null;
- if (lastIndexOfDot == -1) {
- className = classIdentifier;
- } else {
- className = classIdentifier.substring(lastIndexOfDot + 1);
- }
- return className;
- }
-
-
- public static String separate(Collection<? extends Object> elements,
- String separator) {
- StringBuilder s = new StringBuilder();
- boolean first = true;
- for (Object object : elements) {
- if (!first) {
- s.append(separator);
- }
- s.append(object.toString());
- first = false;
- }
- return s.toString();
- }
-
- public static boolean isJavaLangObject(ITypeReference type) {
- if (type instanceof IClassDefinition) {
- IClassDefinition clazz = (IClassDefinition) type;
- if ("java.lang".equals(clazz.getPackageName())) {
- return "Object".equals(clazz.getName());
- }
- }
- return false;
- }
-
-}
diff --git a/tools/signature-tools/src/signature/model/util/TypePool.java b/tools/signature-tools/src/signature/model/util/TypePool.java
deleted file mode 100644
index dc48113..0000000
--- a/tools/signature-tools/src/signature/model/util/TypePool.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.model.util;
-
-import static signature.model.impl.Uninitialized.isInitialized;
-import signature.model.IClassReference;
-import signature.model.IGenericDeclaration;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableReference;
-import signature.model.impl.SigArrayType;
-import signature.model.impl.SigClassDefinition;
-import signature.model.impl.SigClassReference;
-import signature.model.impl.SigParameterizedType;
-import signature.model.impl.SigTypeVariableDefinition;
-import signature.model.impl.SigTypeVariableReference;
-import signature.model.impl.SigWildcardType;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Pool and factory for all {@link ITypeReference} instances.<br>
- * Note: This class is not thread save
- */
-public class TypePool implements ITypeFactory {
-
- /**
- * Pool for all SigClass objects. Key format: "java.lang.Object", "a.b.C$D
- */
- private Map<String, SigClassDefinition> classPool;
- /** Pool for all SigTypeVariable objects */
- private Map<TypeVariableKey, SigTypeVariableDefinition> typeVariablePool;
-
- public TypePool() {
- classPool = new HashMap<String, SigClassDefinition>();
- typeVariablePool =
- new HashMap<TypeVariableKey, SigTypeVariableDefinition>();
- }
-
- public SigClassDefinition getClass(String packageName, String className) {
- String key = packageName + "<>" + className;
- SigClassDefinition clazz = classPool.get(key);
- if (clazz == null) {
- clazz = new SigClassDefinition(packageName, className);
- classPool.put(key, clazz);
- }
- return clazz;
- }
-
- public IClassReference getClassReference(String packageName,
- String className) {
- return new SigClassReference(getClass(packageName, className));
- }
-
- public SigArrayType getArrayType(ITypeReference componentType) {
- assert componentType != null;
- return new SigArrayType(componentType);
- }
-
- public SigParameterizedType getParameterizedType(ITypeReference ownerType,
- IClassReference rawType, List<ITypeReference> typeArguments) {
- assert rawType != null;
- assert typeArguments != null;
- return new SigParameterizedType(ownerType, rawType, typeArguments);
- }
-
- private static class TypeVariableKey {
- private String name;
- private IGenericDeclaration genericDeclaration;
-
- public TypeVariableKey(String name,
- IGenericDeclaration genericDeclaration) {
- this.genericDeclaration = genericDeclaration;
- this.name = name;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + genericDeclaration.hashCode();
- result = prime * result + name.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- TypeVariableKey other = (TypeVariableKey) obj;
- if (genericDeclaration != other.genericDeclaration) {
- return false;
- }
- if (!name.equals(other.name)) {
- return false;
- }
- return true;
- }
- }
-
- public boolean containsTypeVariableDefinition(String name,
- IGenericDeclaration genericDeclaration) {
- TypeVariableKey key = new TypeVariableKey(name, genericDeclaration);
- return typeVariablePool.get(key) != null;
- }
-
- public SigTypeVariableDefinition getTypeVariable(String name,
- IGenericDeclaration genericDeclaration) {
- assert name != null;
- assert genericDeclaration != null;
-
- TypeVariableKey key = new TypeVariableKey(name, genericDeclaration);
- SigTypeVariableDefinition sigTypeVariable = typeVariablePool.get(key);
- if (sigTypeVariable == null) {
- sigTypeVariable = new SigTypeVariableDefinition(name,
- genericDeclaration);
- typeVariablePool.put(key, sigTypeVariable);
- }
- return sigTypeVariable;
- }
-
- public ITypeVariableReference getTypeVariableReference(String name,
- IGenericDeclaration genericDeclaration) {
- return new SigTypeVariableReference(getTypeVariable(name,
- genericDeclaration));
- }
-
- public SigWildcardType getWildcardType(ITypeReference lowerBound,
- List<ITypeReference> upperBounds) {
- assert upperBounds != null;
-
- SigWildcardType sigWildcardType = new SigWildcardType(lowerBound,
- upperBounds);
- return sigWildcardType;
- }
-
- public void replaceAllUninitialiezWithNull() {
- for (SigClassDefinition clazz : classPool.values()) {
- replaceUninitializedWithNull(clazz);
- }
- }
-
- private static void replaceUninitializedWithNull(
- SigClassDefinition clazz) {
- if (clazz == null) {
- return;
- }
- if (!isInitialized(clazz.getAnnotationFields())) {
- clazz.setAnnotationFields(null);
- }
- if (!isInitialized(clazz.getAnnotations())) {
- clazz.setAnnotations(null);
- }
- if (!isInitialized(clazz.getAnnotations())) {
- clazz.setAnnotations(null);
- }
- if (!isInitialized(clazz.getConstructors())) {
- clazz.setConstructors(null);
- }
- if (!isInitialized(clazz.getDeclaringClass())) {
- clazz.setDeclaringClass(null);
- }
-
- if (!isInitialized(clazz.getEnumConstants())) {
- clazz.setEnumConstants(null);
- }
- if (!isInitialized(clazz.getFields())) {
- clazz.setFields(null);
- }
- if (!isInitialized(clazz.getInnerClasses())) {
- clazz.setInnerClasses(null);
- }
- if (!isInitialized(clazz.getInterfaces())) {
- clazz.setInterfaces(null);
- }
- if (!isInitialized(clazz.getKind())) {
- clazz.setKind(null);
- }
- if (!isInitialized(clazz.getMethods())) {
- clazz.setMethods(null);
- }
- if (!isInitialized(clazz.getModifiers())) {
- clazz.setModifiers(null);
- }
- if (!isInitialized(clazz.getSuperClass())) {
- clazz.setSuperClass(null);
- }
- if (!isInitialized(clazz.getTypeParameters())) {
- clazz.setTypeParameters(null);
- }
- }
-}
diff --git a/tools/signature-tools/templates/ApiOverviewPage.st b/tools/signature-tools/templates/ApiOverviewPage.st
deleted file mode 100644
index 4faa193..0000000
--- a/tools/signature-tools/templates/ApiOverviewPage.st
+++ /dev/null
@@ -1,60 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
-<html>
-<head>
-$Common_meta()$
-<title>
-Android API Differences Report
-</title>
-<body>
-<div class="body">
-
-$Header()$
-
-
-<div class="content">
-<h2>Android API Differences Report</h2>
-<p>This document details the changes in the Android framework API. It shows
-additions, modifications, and removals for packages, classes, methods, and
-fields. Each reference to an API change includes a brief description of the
-API and an explanation of the change and suggested workaround, where available.</p>
-
-<p>The differences described in this report are based a comparison of the APIs
-whose versions are specified in the upper-right corner of this page. It compares a
-newer "to" API to an older "from" version, noting any changes relative to the
-older API. So, for example, indicated API removals are no longer present in the "to"
-API.</p>
-<p>For more information about the Android framework API and SDK,
-see the <a href="http://code.google.com/android/index.html" target="_top">Android product site</a>.</p>
-
-$if(no_delta)$
-<h3>Congratulation!</h3>
-No differences were detected between the two provided APIs.
-$endif$
-
-
-$if(removed_packages)$
-$Table(name="Removed Packages", rows=removed_packages:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-
-$if(added_packages)$
-$Table(name="Added Packages", rows=added_packages:{$it.to:PackageAddedLink()$}:SimpleTableRow())$
-<br/>
-$endif$
-
-$if(changed_packages)$
-$Table(name="Changed Packages", rows=changed_packages:{$it.to:PackageChangedLink()$}:SimpleTableRow())$
-<br/>
-$endif$
-</div>
-
-
-</div>
-</body>
-</html>
-
-
-
-
-
diff --git a/tools/signature-tools/templates/ClassChangedLink.st b/tools/signature-tools/templates/ClassChangedLink.st
deleted file mode 100644
index 20e0ed9..0000000
--- a/tools/signature-tools/templates/ClassChangedLink.st
+++ /dev/null
@@ -1 +0,0 @@
-$Link(url={$it.packageName$.$it.name$.html}, name={<tt>$it.name$</tt>})$
diff --git a/tools/signature-tools/templates/ClassOverviewPage.st b/tools/signature-tools/templates/ClassOverviewPage.st
deleted file mode 100644
index 45b4c1c..0000000
--- a/tools/signature-tools/templates/ClassOverviewPage.st
+++ /dev/null
@@ -1,131 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
-<html>
-<head>
-$Common_meta()$
-<title>
-$class_delta.to.packageName$.$class_delta.to.name$
-</title>
-</head>
-<body>
-
-<div class="body">
-
-$Header()$
-
-<div class="content">
-<h2>Class $class_delta.to.packageName$.$class_delta.to:ClassReferenceLink()$</h2>
-<br/>
-
-$if(has_class_signature_delta)$
-<table summary="Signature Difference" border="1" width="100%">
- <tr>
- <th colspan=3>Signature Difference</th>
- </tr>
- <tbody>
- <tr class="default">
- <td>$SigClassDefinition(element=class_delta.to)$</td>
- <td>
- $if(class_delta.annotationDeltas)$ $MultiSubDelta(desc="Annotations Changed:", deltas=class_delta.annotationDeltas)$ $endif$
- $if(class_delta.modifierDeltas)$ $MultiSubDelta(desc="Modifiers Changed:", deltas=class_delta.modifierDeltas)$ $endif$
- $if(class_delta.typeVariableDeltas)$ $MultiSubDelta(desc="Type Variables Changed:", deltas=class_delta.typeVariableDeltas)$ $endif$
- $if(class_delta.superClassDelta)$ $SingleSubDelta(desc="Superclass Changed", delta=class_delta.superClassDelta)$ $endif$
- $if(class_delta.interfaceDeltas)$ $MultiSubDelta(desc="Interfaces Changed:", deltas=class_delta.interfaceDeltas)$ $endif$
- </td>
- </tr>
- </tbody>
-</table>
-<br/>
-$endif$
-
-$! Annotation Fields !$
-
-$if(removed_annotation_fields)$
-$Table(name="Removed Annotation Fields", rows=removed_annotation_fields:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(added_annotation_fields)$
-$Table(name="Added Annotation Fields", rows=added_annotation_fields:{$it.to:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(changed_annotation_fields)$
-$Table(name="Changed Annotation Fields", rows=changed_annotation_fields:DeltaTableRow())$
-<br/>
-$endif$
-
-
-$! --------Enum Constants-------- !$
-
-$if(removed_enum_constants)$
-$Table(name="Removed Enum Constants", rows=removed_enum_constants:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(added_enum_constants)$
-$Table(name="Added Enum Constants", rows=added_enum_constants:{$it.to:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(changed_enum_constants)$
-$Table(name="Changed Enum Constants", rows=changed_enum_constants:DeltaTableRow())$
-<br/>
-$endif$
-
-
-$! Fields !$
-
-$if(removed_fields)$
-$Table(name="Removed Fields", rows=removed_fields:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(added_fields)$
-$Table(name="Added Fields", rows=added_fields:{$it.to:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(changed_fields)$
-$Table(name="Changed Fields", rows=changed_fields:DeltaTableRow())$
-<br/>
-$endif$
-
-
-$! Constructors !$
-
-$if(removed_constructors)$
-$Table(name="Removed Constructors", rows=removed_constructors:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(added_constructors)$
-$Table(name="Added Constructors", rows=added_constructors:{$it.to:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(changed_constructors)$
-$Table(name="Changed Constructors", rows=changed_constructors:DeltaTableRow())$
-<br/>
-$endif$
-
-
-$! Methods !$
-
-$if(removed_methods)$
-$Table(name="Removed Methods", rows=removed_methods:{$it.from:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(added_methods)$
-$Table(name="Added Methods", rows=added_methods:{$it.to:ModelElementRow()$})$
-<br/>
-$endif$
-
-$if(changed_methods)$
-$Table(name="Changed Methods", rows=changed_methods:DeltaTableRow())$
-<br/>
-$endif$
-</div>
-</div>
-</body>
-</html>
\ No newline at end of file
diff --git a/tools/signature-tools/templates/ClassReferenceLink.st b/tools/signature-tools/templates/ClassReferenceLink.st
deleted file mode 100644
index c22e9b5..0000000
--- a/tools/signature-tools/templates/ClassReferenceLink.st
+++ /dev/null
@@ -1 +0,0 @@
-$Link(url={http://code.google.com/android/reference/$it.packageFragments; separator="/"$/$it.name$.html}, name={<tt>$it.name$</tt>})$
diff --git a/tools/signature-tools/templates/Common_meta.st b/tools/signature-tools/templates/Common_meta.st
deleted file mode 100644
index 8663781..0000000
--- a/tools/signature-tools/templates/Common_meta.st
+++ /dev/null
@@ -1,12 +0,0 @@
-<meta name="generator" content="Android signature tools v 1.0">
-<meta name="keywords" content="API difference, difference between two APIs, API diff">
-<link type="text/css" rel="stylesheet" href="../styles.css" title="Stylesheet"/>
-<link type="text/css" rel="stylesheet" href="styles.css" title="Stylesheet"/>
-
-<link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/codesite/codesite.css"/>
-<link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/codesite/semantic_headers.css"/>
-<link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/style.css"/>
-
-
-
-
diff --git a/tools/signature-tools/templates/DeltaTableRow.st b/tools/signature-tools/templates/DeltaTableRow.st
deleted file mode 100644
index 4d0974c..0000000
--- a/tools/signature-tools/templates/DeltaTableRow.st
+++ /dev/null
@@ -1,8 +0,0 @@
-<tr class="deltaTableRow">
- <td class="element">
- $ElementType(element=it.to):{<tt>$it$</tt>}$
- </td>
- <td class="delta">
- $DeltaTypeSwitch(delta=it)$
- </td>
-</tr>
diff --git a/tools/signature-tools/templates/Header.st b/tools/signature-tools/templates/Header.st
deleted file mode 100644
index 9aa8e2f..0000000
--- a/tools/signature-tools/templates/Header.st
+++ /dev/null
@@ -1,21 +0,0 @@
-<div class="header">
- <div class="logo">
- <a href="http://code.google.com/android/documentation.html"><img style="border: 0;" src="http://code.google.com/android/images/android_icon_125.png"/></a>
- </div>
- <div class="specbox">
- <table>
- <tr>
- <th colspan="2"> API Diff Specification </th>
- </tr>
- <tr>
- <td>To Version:</td> <td>$to_desc$</td>
- </tr>
- <tr>
- <td>From Version:</td> <td>$from_desc$</td>
- </tr>
- <tr>
- <td>Generated</td> <td>$creation_time$</td>
- </tr>
- </table>
- </div>
-</div>
\ No newline at end of file
diff --git a/tools/signature-tools/templates/Link.st b/tools/signature-tools/templates/Link.st
deleted file mode 100644
index 2421094..0000000
--- a/tools/signature-tools/templates/Link.st
+++ /dev/null
@@ -1 +0,0 @@
-<a class="$link_style; null="default"$" href="$url$">$name$</a>
\ No newline at end of file
diff --git a/tools/signature-tools/templates/ModelElementRow.st b/tools/signature-tools/templates/ModelElementRow.st
deleted file mode 100644
index 54b20c6..0000000
--- a/tools/signature-tools/templates/ModelElementRow.st
+++ /dev/null
@@ -1,6 +0,0 @@
-<tr class="deltaTableRow">
- <td class="element">
- $ElementType(element=it):{<tt>$it$</tt>}$
- </td>
-</tr>
-
diff --git a/tools/signature-tools/templates/PackageAddedLink.st b/tools/signature-tools/templates/PackageAddedLink.st
deleted file mode 100644
index eb352da..0000000
--- a/tools/signature-tools/templates/PackageAddedLink.st
+++ /dev/null
@@ -1 +0,0 @@
-$Link(url={http://code.google.com/android/reference/$it.packageFragments; separator="/"$/package-summary.html}, name={<tt>$it.name$</tt>})$
diff --git a/tools/signature-tools/templates/PackageChangedLink.st b/tools/signature-tools/templates/PackageChangedLink.st
deleted file mode 100644
index 5951f2a..0000000
--- a/tools/signature-tools/templates/PackageChangedLink.st
+++ /dev/null
@@ -1 +0,0 @@
-$Link(url={changes/pkg_$it.name$.html}, name={<tt>$it.name$</tt>})$
\ No newline at end of file
diff --git a/tools/signature-tools/templates/PackageOverviewPage.st b/tools/signature-tools/templates/PackageOverviewPage.st
deleted file mode 100644
index ebeded0..0000000
--- a/tools/signature-tools/templates/PackageOverviewPage.st
+++ /dev/null
@@ -1,39 +0,0 @@
-<!doctype html public "-//w3c//dtd html 4.0 frameset//en""http://www.w3.org/tr/rec-html40/frameset.dtd">
-<html>
-<head>
-$Common_meta()$
-<title>
-Android API Differences Report
-</title>
-<body>
-
-<div class="body">
-
-$Header()$
-
-<div class="content">
-
-<h2>
-Package $Link(url={http://code.google.com/android/reference/$package_delta.to.packageFragments; separator="/"$/package-summary.html}, name=package_delta.to.name)$
-</h2>
-
-
-$if(removed_classes)$
-$Table(name="Removed Classes and Interfaces", rows=removed_classes:{$it.from:{<tt>$it.name$</tt>}$}:SimpleTableRow())$
-<br/>
-$endif$
-
-
-$if(added_classes)$
-$Table(name="Added Classes and Interfaces", rows=added_classes:{$it.to:ClassReferenceLink()$}:SimpleTableRow())$
-<br/>
-$endif$
-
-$if(changed_classes)$
-$Table(name="Changed Classes and Interfaces", rows=changed_classes:{$it.to:ClassChangedLink()$}:SimpleTableRow())$
-<br/>
-$endif$
-</div>
-</div>
-</body>
-</html>
\ No newline at end of file
diff --git a/tools/signature-tools/templates/SimpleTableRow.st b/tools/signature-tools/templates/SimpleTableRow.st
deleted file mode 100644
index 3e7e7c2..0000000
--- a/tools/signature-tools/templates/SimpleTableRow.st
+++ /dev/null
@@ -1,5 +0,0 @@
-<tr class="default">
- <td>
- $it$
- </td>
-</tr>
diff --git a/tools/signature-tools/templates/Styles.st b/tools/signature-tools/templates/Styles.st
deleted file mode 100644
index 4294eb3..0000000
--- a/tools/signature-tools/templates/Styles.st
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Noser signature html output v$version$
- */
-
-/* default link style*/
-a.default:link {color: blue; text-decoration: none}
-a.default:hover {color: blue; text-decoration: underline;}
-a.default:visited {color: blue; text-decoration: none}
-
-/* discreet link style */
-a.discreet:link {color: black; text-decoration: none}
-a.discreet:visited {color: black; text-decoration: none}
-a.discreet:hover {color: black; text-decoration: underline;}
-
-ul {
- list-style-type: none
-}
-
-.body {
- margin: 10px;
-}
-
-.header {
- position:relative;
- width: 100%;
-
-}
-
-.logo {
- left:0px;
-}
-.specbox {
- position:absolute;
- right:0px;
- top:0px;
-}
-
-.content {
- width: 100%;
- position: relative;
- top:75px;
-}
-
-
diff --git a/tools/signature-tools/templates/Table.st b/tools/signature-tools/templates/Table.st
deleted file mode 100644
index 2eecb8e..0000000
--- a/tools/signature-tools/templates/Table.st
+++ /dev/null
@@ -1,9 +0,0 @@
-<table summary="$name$" border="1" width="100%">
-<tr>
- <th COLSPAN=2>$name$</th>
-</tr>
-<tbody>
-$rows$
-</tbody>
-</table>
-
diff --git a/tools/signature-tools/templates/delta/deltas.stg b/tools/signature-tools/templates/delta/deltas.stg
deleted file mode 100644
index a27d641..0000000
--- a/tools/signature-tools/templates/delta/deltas.stg
+++ /dev/null
@@ -1,149 +0,0 @@
-group deltas;
-
-
-ADDED(delta) ::= "Added $ElementType(element=delta.to)$"
-
-
-REMOVED(delta) ::= "Removed $ElementType(element=delta.from)$"
-
-
-CHANGED(delta) ::= "$DeltaType(delta)$"
-
-
-DeltaType(delta) ::= "$({$delta.class.simpleName$})(delta)$"
-
-
-DeltaTypeSwitch(delta) ::= "$delta:({$delta.type$})(delta)$"
-
-
-MultiSubDelta(desc, deltas) ::= <<
-$if(deltas)$
-$if(!deltas.empty)$
-$desc$
-<ul>
-$deltas:{<li>$DeltaTypeSwitch(delta=it)$</li>}$
-</ul>
-$endif$
-$endif$
->>
-
-
-SigAnnotationDelta(delta) ::= <<
-$MultiSubDelta(desc="Annotation Elements changed:", deltas=delta.annotationElementDeltas)$
->>
-
-
-
-SigAnnotationElementDelta(delta) ::= <<
-$SingleSubDelta(desc="Value changed:", delta=delta.valueDelta)$
->>
-
-
-SigArrayTypeDelta(delta) ::= <<
-$SingleSubDelta(desc="Component Type of array changed:", delta=delta.componentTypeDelta)$
->>
-
-
-SigClassReferenceDelta(delta) ::= "from $SigClass(element=delta.from)$ to $SigClass(element=delta.to)$"
-
-
-SigConstructorDelta(delta) ::= "$SigExecutableMemberDelta(delta=delta)$"
-
-SigMethodDelta(delta) ::= <<
-$SigExecutableMemberDelta(delta=delta)$
-$if(delta.returnTypeDelta)$
-$SingleSubDelta(desc="Return Type changed:", delta=delta.returnTypeDelta)$
-$endif$
->>
-
-
-SigExecutableMemberDelta(delta) ::= <<
-$if(delta.annotationDeltas)$
-$MultiSubDelta(desc="Annotations changed:", deltas=delta.annotationDeltas)$
-$endif$
-
-$if(delta.modifierDeltas)$
-$MultiSubDelta(desc="Modifiers changed:", deltas=delta.modifierDeltas)$
-$endif$
-
-$if(delta.typeVariableDeltas)$
-$MultiSubDelta(desc="Type Variables changed:", deltas=delta.typeVariableDeltas)$
-$endif$
-
-$if(delta.exceptionDeltas)$
-$MultiSubDelta(desc="Exceptions changed:", deltas=delta.exceptionDeltas)$
-$endif$
-
-$if(delta.parameterDeltas)$
-$MultiSubDelta(desc="Parameters changed:", deltas=delta.parameterDeltas)$
-$endif$
->>
-
-SigFieldDelta(delta) ::= <<
-$SingleSubDelta(desc="Type changed:", delta=delta.typeDelta)$
-$MultiSubDelta(desc="Modifiers changed:", deltas=delta.modifierDeltas)$
-$MultiSubDelta(desc="Annotations changed:", deltas=delta.annotationDeltas)$
->>
-
-SigGenericDelclarationDelta(delta) ::= "GenericDelclarationDelta $delta$"
-
-SigModifierDelta(delta) ::= "SigModifierDelta.st: Please file a bug if you see this message"
-
-
-SigParameterDelta(delta) ::= <<
-$if(delta.annotationDeltas)$
-$MultiSubDelta(desc="Annotations changed:", deltas=delta.annotationDeltas)$
-$endif$
-
-$if(delta.typeDelta)$
-$SingleSubDelta(desc="Type changed:", delta=delta.typeDelta)$
-$endif$
->>
-
-
-SigParameterizedTypeDelta(delta) ::= <<
-$SingleSubDelta(desc="Owner Type changed:", delta=delta.ownerTypeDelta)$
-$SingleSubDelta(desc="Raw Type changed:", delta=delta.rawTypeDelta)$
-$MultiSubDelta(desc="Type Arguments changed:", deltas=delta.argumentTypeDeltas)$
->>
-
-
-SigPrimitiveTypeDelta(delta) ::= "from $delta.from$ to $delta.to$"
-
-SigTypeDelta(delta) ::= "from $ElementType(element=delta.from)$ to $ElementType(element=delta.to)$"
-
-SigTypeVariableReferenceDelta(delta) ::= <<
-SigTypeVariableReferenceDelta:
-$delta$
->>
-
-SigTypeVariableDefinitionDelta(delta) ::= <<
-$SingleSubDelta(desc="Upper Bound changed:", delta=delta.upperBoundsDelta)$
-$SingleSubDelta(desc="Declaration changed:", delta=delta.genericDeclarationDelta)$
->>
-
-SigUpperBoundsDelta(delta) ::= <<
-$SingleSubDelta(desc="First Upper Bound changed:", delta=delta.firstUpperBoundDelta)$
-$MultiSubDelta(desc="Upper Bounds changed:", deltas=delta.remainingUpperBoundDeltas)$
->>
-
-SigWildcardTypeDelta(delta) ::= <<
-$SingleSubDelta(desc="Lower Bound changed:", delta=delta.lowerBoundDelta)$
-$SingleSubDelta(desc="Upper Bounds changed:", delta=delta.upperBoundDelta)$
->>
-
-SigAnnotationFieldDelta(delta) ::= <<
-$SigFieldDelta(delta = delta)$
-$SingleSubDelta(desc="Default value changed:", delta=delta.defaultValueDelta)$
->>
-
-SingleSubDelta(desc, delta) ::= <<
-$if(delta)$
-$desc$
-<ul>
- <li>$DeltaTypeSwitch(delta=delta)$</li>
-</ul>
-$endif$
->>
-
-
diff --git a/tools/signature-tools/templates/model/model.stg b/tools/signature-tools/templates/model/model.stg
deleted file mode 100644
index 425ad36..0000000
--- a/tools/signature-tools/templates/model/model.stg
+++ /dev/null
@@ -1,135 +0,0 @@
-group model;
-
-ElementType(element) ::= <<
-$({$element.class.simpleName$})(element = element)$
->>
-
-Modifier(element) ::= <<
-$element$
->>
-
-SigAnnotation(element) ::= <<
-@$ElementType(element = element.type)$
-$if(element.elements)$
-{$element.elements:{$SigAnnotationElement(element=it)$}$}
-$endif$
->>
-
-SigAnnotationElement(element) ::= <<
-$element.declaringField.name$=$element.value$
->>
-
-SigAnnotationField(element) ::= <<
-$SigField(element = element)$ $if(element.defaultValue)$ default=$element.defaultValue$$endif$
->>
-
-SigArrayType(element) ::= <<
-$ElementType(element = element.componentType)$[]
->>
-
-
-SigClassDefinition(element) ::= <<
-$Annotations(element = element)$
-$Modifiers(element = element)$$element.kind$ $element:ClassReferenceLink(link_style="discreet")$
-$TypeParameters(element = element)$
-$if(element.superClass)$ extends $ElementType(element=element.superClass)$$endif$
-$if(element.interfaces)$ implements $element.interfaces:{$ElementType(element=it)$}; separator=", "$$endif$
->>
-
-ClassReferenceProjection(element) ::= <<
-$SigClassReference(element= element)$
->>
-
-SigClassReference(element) ::= <<
-$ClassReferenceLink(it = element.classDefinition, link_style="discreet")$
->>
-
-SigConstructor(element) ::= <<
-$Annotations(element= element, separator=" ")$
-$Modifiers(element= element)$
-$TypeParameters(element= element)$
-$SigExecutableMember(element= element)$
->>
-
-//FIXME add SigEnumConstantReference to format correct in either case
-SigEnumConstant(element) ::= <<
-enum constant $ElementType(element=element.type)$.$element.name$
->>
-
-SigExecutableMember(element) ::= <<
-$element.name$($element.parameters:{$SigParameter(element=it)$}; separator=", "$)
-$if(element.exceptions)$ throws $element.exceptions:{$ElementType(element=it)$}; separator=", "$$endif$
->>
-
-SigField(element) ::= <<
-$Annotations(element = element, separator="<br/>")$
-$Modifiers(element = element)$$ElementType(element=element.type)$ $element.name$
->>
-
-MethodProjection(element) ::= <<
-$SigMethod(element=element)$
->>
-
-SigMethod(element) ::= <<
-$Annotations(element=element)$
-$Modifiers(element=element)$
-$TypeParameters(element=element)$
-$ElementType(element=element.returnType)$ $SigExecutableMember(element = element)$
->>
-
-SigPackage(element) ::= <<
-$element.name$
->>
-
-SigParameter(element) ::= <<
-$Annotations(element = element, separator=" ")$
-$ElementType(element=element.type)$
->>
-
-ParameterizedTypeProjection(element) ::= <<
-$SigParameterizedType(element = element)$
->>
-
-SigParameterizedType(element) ::= <<
-$if(element.ownerType)$$ElementType(element=element.ownerType)$$endif$
-$SigClassReference(element=element.rawType)$
-$if(element.typeArguments)$<$element.typeArguments:{$ElementType(element=it)$}$>$endif$
->>
-
-SigPrimitiveType(element) ::= <<
-$element.name$
->>
-
-SigTypeVariableDefinition(element) ::= <<
-$element.name$$if(!element.upperBounds.empty)$ extends $element.upperBounds:{$ElementType(element=it)$}; separator=", "$$endif$
->>
-
-SigTypeVariableReference(element) ::= <<
-$element.typeVariableDefinition.name$
->>
-
-SigWildcardType(element) ::= <<
-?
-$if(element.lowerBound)$ super $ElementType(element=element.lowerBound)$$endif$
-$if(!element.upperBounds.empty)$ extends $element.upperBounds:{$ElementType(element=it)$}; separator=", "$$endif$
->>
-
-
-/* helper templates*/
-
-Modifiers(element) ::= <<
-$if(element.modifiers)$
-$element.modifiers; separator=" "$$\ $
-$endif$
->>
-
-Annotations(element, separator) ::= <<
-$if(element.annotations)$
-$element.annotations:{$SigAnnotation(element=it)$}; separator=separator$
-$separator$
-$endif$
->>
-
-TypeParameters(element) ::= <<
-$if(element.typeParameters)$ <$element.typeParameters:{$SigTypeVariableDefinition(element=it)$}; separator=", "$>$endif$
->>
diff --git a/tools/signature-tools/test/signature/comparator/AllDexTests.java b/tools/signature-tools/test/signature/comparator/AllDexTests.java
deleted file mode 100644
index b44dcb6..0000000
--- a/tools/signature-tools/test/signature/comparator/AllDexTests.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-import signature.converter.dex.DexTestConverter;
-import signature.converter.util.ITestSourceConverter;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllDexTests.DexPackageCompareTest.class,
- AllDexTests.DexClassCompareTest.class,
- AllDexTests.DexMethodCompareTests.class,
- AllDexTests.DexAnnotationCompareTest.class
-})
-public class AllDexTests {
- private static ITestSourceConverter newConverter(){
- return new DexTestConverter();
- }
-
- public static class DexPackageCompareTest extends PackageCompareTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class DexClassCompareTest extends ClassCompareTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class DexMethodCompareTests extends MethodCompareTests {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class DexAnnotationCompareTest extends AnnotationCompareTest{
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/tools/signature-tools/test/signature/comparator/AllDocletTests.java b/tools/signature-tools/test/signature/comparator/AllDocletTests.java
deleted file mode 100644
index 327d931..0000000
--- a/tools/signature-tools/test/signature/comparator/AllDocletTests.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-import signature.converter.doclet.DocletTestConverter;
-import signature.converter.util.ITestSourceConverter;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllDocletTests.DocletPackageCompareTest.class,
- AllDocletTests.DocletClassCompareTest.class,
- AllDocletTests.DocletMethodCompareTests.class
-})
-public class AllDocletTests {
- private static ITestSourceConverter newConverter(){
- return new DocletTestConverter();
- }
-
- public static class DocletPackageCompareTest extends PackageCompareTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class DocletClassCompareTest extends ClassCompareTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class DocletMethodCompareTests extends MethodCompareTests {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-}
\ No newline at end of file
diff --git a/tools/signature-tools/test/signature/comparator/AnnotationCompareTest.java b/tools/signature-tools/test/signature/comparator/AnnotationCompareTest.java
deleted file mode 100644
index c72b637..0000000
--- a/tools/signature-tools/test/signature/comparator/AnnotationCompareTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-
-import signature.comparator.util.AbstractComparatorTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-
-import java.io.IOException;
-
-public abstract class AnnotationCompareTest extends AbstractComparatorTest {
-
- @Test
- public void testAnnotationValue() throws IOException{
- CompilationUnit A0 = new CompilationUnit("a.A0",
- "package a; " +
- "public @interface A0 {" +
- " A1 value() default @A1;" +
- "}");
- CompilationUnit A1 = new CompilationUnit("a.A1",
- "package a; " +
- "public @interface A1 {" +
- "}");
- CompilationUnit AnnotBDefault = new CompilationUnit("a.B",
- "package a; " +
- "@A0 " +
- "public class B {}");
- CompilationUnit AnnotB = new CompilationUnit("a.B",
- "package a; " +
- "@A0 " +
- "public class B {}");
- IApi fromApi = convert(A0, A1, AnnotBDefault);
- IApi toApi = convert(A0, A1, AnnotB);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void testDefaultAnnotationValue() throws IOException{
- CompilationUnit A0 = new CompilationUnit("a.A0",
- "package a; " +
- "public @interface A0 {" +
- " String value() default \"bla\";" +
- "}");
- CompilationUnit A1 = new CompilationUnit("a.A0",
- "package a; " +
- "public @interface A0 {" +
- " String value();" +
- "}");
- IApi fromApi = convert(A0);
- IApi toApi = convert(A1);
- assertNotNull(compare(fromApi, toApi));
- }
-}
diff --git a/tools/signature-tools/test/signature/comparator/ClassCompareTest.java b/tools/signature-tools/test/signature/comparator/ClassCompareTest.java
deleted file mode 100644
index 7171978..0000000
--- a/tools/signature-tools/test/signature/comparator/ClassCompareTest.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-
-import signature.comparator.util.AbstractComparatorTest;
-import signature.compare.model.IAnnotationDelta;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.DeltaType;
-import signature.compare.model.ITypeReferenceDelta;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-
-import java.io.IOException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.util.Set;
-
-public abstract class ClassCompareTest extends AbstractComparatorTest {
-
- @Test
- public void compareEqualClasses() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B {}");
- IApi fromApi = convert(A, B);
- IApi toApi = convert(A, B);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void compareMissingClass() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B {}");
- IApi fromApi = convert(A, B);
- IApi toApi = convert(A);
-
- IApiDelta delta = compare(fromApi, toApi);
- IClassDefinitionDelta classDelta = getSingleClassDelta(delta);
- assertSame(DeltaType.REMOVED, classDelta.getType());
- }
-
- @Test
- public void compareAddedClass() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B {}");
- IApi fromApi = convert(A);
- IApi toApi = convert(A, B);
-
- IApiDelta delta = compare(fromApi, toApi);
- IClassDefinitionDelta classDelta = getSingleClassDelta(delta);
- assertSame(DeltaType.ADDED, classDelta.getType());
- }
-
- @Test
- public void compareAnnotationsOnClass() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit AnnotA = new CompilationUnit("a.A",
- "package a; " +
- "@Deprecated " +
- "public class A {}");
- IApi fromApi = convert(A);
- IApi toApi = convert(AnnotA);
-
- IApiDelta delta = compare(fromApi, toApi);
- IClassDefinitionDelta classDelta = getSingleClassDelta(delta);
-
- System.out.println(classDelta);
-
- Set<IAnnotationDelta> annotationDeltas = classDelta.getAnnotationDeltas();
- assertEquals(1, annotationDeltas.size());
-
- IAnnotationDelta annotationDelta = annotationDeltas.iterator().next();
- assertSame(DeltaType.ADDED, annotationDelta.getType());
- }
-
- @Test
- public void compareDefaultedAnnotationElementOnClass() throws IOException{
- CompilationUnit annot = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " String name() default \"NAME\" ;" +
- "}");
- CompilationUnit AnnotBDefault = new CompilationUnit("a.B",
- "package a; " +
- "@A " +
- "public class B {}");
- CompilationUnit AnnotB = new CompilationUnit("a.B",
- "package a; " +
- "@A(name=\"NAME\") " +
- "public class B {}");
- IApi fromApi = convert(annot, AnnotBDefault);
- IApi toApi = convert(annot, AnnotB);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void compareSameInterfaces() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A implements Comparable<String>{ " +
- " public int compareTo(String another){return 0;}" +
- "}");
- IApi fromApi = convert(A);
- IApi toApi = convert(A);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void compareMissingInterface() throws IOException{
- CompilationUnit A0 = new CompilationUnit("a.A",
- "package a; " +
- "public class A implements Cloneable{}");
- CompilationUnit A1 = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- IApi fromApi = convert(A0);
- IApi toApi = convert(A1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- IClassDefinitionDelta classDelta = getSingleClassDelta(apiDelta);
- assertEquals(1, classDelta.getInterfaceDeltas().size());
- ITypeReferenceDelta<?> interfaceDelta = classDelta.getInterfaceDeltas().iterator().next();
- assertNotNull(interfaceDelta);
- }
-
- @Test
- public void compareMissingGenericInterface0() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T>{}");
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B implements I<String>{}");
- CompilationUnit A0 = new CompilationUnit("a.A",
- "package a; " +
- "public class A extends B implements I<String>{}");
- CompilationUnit A1 = new CompilationUnit("a.A",
- "package a; " +
- "public class A extends B {}");
- IApi fromApi = convert(I, B, A0);
- IApi toApi = convert(I, B, A1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingGenericInterface1() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T>{}");
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B<T> implements I<T>{}");
- CompilationUnit A0 = new CompilationUnit("a.A",
- "package a; " +
- "public class A<T> extends B<T> implements I<T>{}");
- //generic declaration of 'T' in I<T> is A<T>
- CompilationUnit A1 = new CompilationUnit("a.A",
- "package a; " +
- "public class A<T> extends B<T> {}");
- //generic declaration of 'T' in I<T> is B<T>
- IApi fromApi = convert(I, B, A0);
- IApi toApi = convert(I, B, A1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- static interface I<T>{}
- static class B<T> implements I<T>{}
- static class A0<E extends Number> extends B<E> implements I<E>{}
- static class A1<S extends Number> extends B<S>{}
-
- @Test
- public void compareMissingGenericInterfaceReflection() {
- ParameterizedType sC = (ParameterizedType)A0.class.getGenericSuperclass();
- Type[] bounds = ((TypeVariable<?>)sC.getActualTypeArguments()[0]).getBounds();
- Type[] a1Int = A1.class.getGenericInterfaces();
- assertEquals(0,a1Int.length);
- }
-
- @Test
- public void compareInterfaceClosure() throws IOException{
- CompilationUnit I0 = new CompilationUnit("a.I0",
- "package a; " +
- "public interface I0{}");
- CompilationUnit I1 = new CompilationUnit("a.I1",
- "package a; " +
- "public interface I1 extends I0{}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 implements I1{}");
- CompilationUnit C0_I1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 implements I1, I0{}");
- IApi fromApi = convert(I0, I1, C0);
- IApi toApi = convert(I0, I1, C0_I1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareUpperBounds0() throws IOException{
- CompilationUnit Number = new CompilationUnit("a.Number",
- "package a; " +
- "public class Number implements java.io.Serializable{}");
- CompilationUnit I0 = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T extends Number & java.io.Serializable>{}");
- CompilationUnit I1 = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T extends Number>{}");
- IApi fromApi = convert(I0,Number);
- IApi toApi = convert(I1,Number);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareUpperBounds1() throws IOException{
- CompilationUnit Number = new CompilationUnit("a.Number",
- "package a; " +
- "public class Number {}");
- CompilationUnit I0 = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T extends Number & java.io.Serializable>{}");
- CompilationUnit I1 = new CompilationUnit("a.I",
- "package a; " +
- "public interface I<T extends Number>{}");
- IApi fromApi = convert(I0,Number);
- IApi toApi = convert(I1,Number);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void compareTypeVariables0() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T,S> {}");
- CompilationUnit C1 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<S,T> {}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareTypeVariables1() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T,S> {}");
- CompilationUnit C1 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T,S,R> {}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void compareTypeVariables2() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T,S> {" +
- " public void m(T t, S s){} " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<S,T> {" +
- " public void m(S s, T t){} " +
- "}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareTypeVariables3() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T,S> {" +
- " public void m(T t, S s){} " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<S,T> {" +
- " public void m(T t, S s){} " +
- "}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void compareTypeVariables4() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C",
- "package a; " +
- "public class C<T> {" +
- " public class I{" +
- " public void m(T t){}" +
- " } " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C",
- "package a; " +
- "public class C {" +
- " public class I<T>{" +
- " public void m(T t){}" +
- " } " +
- "}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void interfaceClosureTest() throws IOException{
- CompilationUnit B = new CompilationUnit("a.B",
- "package a; " +
- "public class B<S> {}");
- CompilationUnit C = new CompilationUnit("a.C",
- "package a; " +
- "public class C<R> extends B<R> {}");
- CompilationUnit E = new CompilationUnit("a.E",
- "package a; " +
- "public class E<Q> extends C<Q> {}");
- CompilationUnit F = new CompilationUnit("a.F",
- "package a; " +
- "public class F<P> extends E<P> {}");
- CompilationUnit G = new CompilationUnit("a.G",
- "package a; " +
- "public class G<O> extends F<O> {}");
- CompilationUnit H = new CompilationUnit("a.H",
- "package a; " +
- "public class H<R> extends G<R> {}");
-// IApi fromApi = convert(B,C, E, F);
-// IApi toApi = convert(B,C,E, F);
- IApi fromApi = convert(B,C, E,F, G, H);
- IApi toApi = convert(B,C,E,F, G, H);
-
-
- long start = System.currentTimeMillis();
- IApiDelta apiDelta = compare(fromApi, toApi);
- System.out.println("compare took :" + (System.currentTimeMillis() -start) + "ms");
- assertNull(apiDelta);
- }
-
-}
\ No newline at end of file
diff --git a/tools/signature-tools/test/signature/comparator/MethodCompareTests.java b/tools/signature-tools/test/signature/comparator/MethodCompareTests.java
deleted file mode 100644
index 3e94506..0000000
--- a/tools/signature-tools/test/signature/comparator/MethodCompareTests.java
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.io.IOException;
-
-import org.junit.Test;
-
-import signature.comparator.util.AbstractComparatorTest;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.DeltaType;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-
-public abstract class MethodCompareTests extends AbstractComparatorTest {
-
-
- @Test
- public void compareEqualClasses() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(){}" +
- "}");
- IApi fromApi = convert(A);
- IApi toApi = convert(A);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void compareMissingMethod() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(){}" +
- "}");
- CompilationUnit AMissing = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- "}");
- IApi fromApi = convert(A);
- IApi toApi = convert(AMissing);
- IApiDelta delta = compare(fromApi, toApi);
- assertNotNull(delta);
- IClassDefinitionDelta classDelta = delta.getPackageDeltas().iterator().next().getClassDeltas().iterator().next();
- assertEquals(1, classDelta.getMethodDeltas().size());
- assertEquals(DeltaType.REMOVED, classDelta.getMethodDeltas().iterator().next().getType());
- }
-
- @Test
- public void compareAddedMethod() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(){}" +
- "}");
- CompilationUnit AMissing = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- "}");
- IApi fromApi = convert(AMissing);
- IApi toApi = convert(A);
- IApiDelta delta = compare(fromApi, toApi);
- assertNotNull(delta);
- IClassDefinitionDelta classDelta = delta.getPackageDeltas().iterator().next().getClassDeltas().iterator().next();
- assertEquals(1, classDelta.getMethodDeltas().size());
- assertEquals(DeltaType.ADDED, classDelta.getMethodDeltas().iterator().next().getType());
- }
-
- @Test
- public void compareChangedMethod() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(){}" +
- "}");
- CompilationUnit AMissing = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m() throws Exception {}" +
- "}");
- IApi fromApi = convert(AMissing);
- IApi toApi = convert(A);
- IApiDelta delta = compare(fromApi, toApi);
- assertNotNull(delta);
- IClassDefinitionDelta classDelta = delta.getPackageDeltas().iterator().next().getClassDeltas().iterator().next();
- assertEquals(1, classDelta.getMethodDeltas().size());
- assertEquals(DeltaType.CHANGED, classDelta.getMethodDeltas().iterator().next().getType());
- }
-
- @Test
- public void compareAddedParameterMethod() throws IOException{
- CompilationUnit A = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(){}" +
- "}");
- CompilationUnit AMissing = new CompilationUnit("a.A",
- "package a; " +
- "public class A {" +
- " public void m(int i) {}" +
- "}");
- IApi fromApi = convert(AMissing);
- IApi toApi = convert(A);
- IApiDelta delta = compare(fromApi, toApi);
- assertNotNull(delta);
- IClassDefinitionDelta classDelta = delta.getPackageDeltas().iterator().next().getClassDeltas().iterator().next();
- assertEquals(2, classDelta.getMethodDeltas().size()); //one added , one removed
- }
-
- @Test
- public void compareExceptions0() throws IOException{
- CompilationUnit E0 = new CompilationUnit("a.E0",
- "package a; " +
- "public class E0 extends Exception {}");
- CompilationUnit E1 = new CompilationUnit("a.E1",
- "package a; " +
- "public class E1 extends E0 {}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 {" +
- " public void m() throws E0 {}" +
- "}");
- CompilationUnit C0_E1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0{" +
- " public void m() throws E0, E1 {}" +
- "}");
- IApi fromApi = convert(E0, E1, C0);
- IApi toApi = convert(E0, E1, C0_E1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareExceptions1() throws IOException{
- CompilationUnit E0 = new CompilationUnit("a.E0",
- "package a; " +
- "public class E0 extends Exception {}");
- CompilationUnit E1 = new CompilationUnit("a.E1",
- "package a; " +
- "public class E1 extends Exception {}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 {" +
- " public void m() throws E0 {}" +
- "}");
- CompilationUnit C0_E1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0{" +
- " public void m() throws E0, E1 {}" +
- "}");
- IApi fromApi = convert(E0, E1, C0);
- IApi toApi = convert(E0, E1, C0_E1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void compareRuntimeExceptions() throws IOException{
- CompilationUnit E0 = new CompilationUnit("a.E0",
- "package a; " +
- "public class E0 extends RuntimeException {}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0{" +
- " public void m() {}" +
- "}");
- CompilationUnit C0_E0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 {" +
- " public void m() throws E0 {}" +
- "}");
- IApi fromApi = convert(E0, C0);
- IApi toApi = convert(E0, C0_E0);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareAnnotations() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0{" +
- " public void m(int i) {}" +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 {" +
- " public void m(@Deprecated int i) {}" +
- "}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
- }
-
- @Test
- public void compareMissingDefaultConstructor() throws IOException{
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0{" +
- " public C0() {}" +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 {}");
- IApi fromApi = convert(C0);
- IApi toApi = convert(C1);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingAbstractMethod() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public interface I{" +
- " void m();" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public abstract class C0 implements I{" +
- " public abstract void m(); " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public abstract class C0 implements I{}");
- IApi fromApi = convert(C0, I);
- IApi toApi = convert(C1, I);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethod() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public class I{" +
- " public void m(){};" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 extends I{" +
- " public void m(){}; " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0 extends I{}");
- IApi fromApi = convert(C0, I);
- IApi toApi = convert(C1, I);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethodGeneric0() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public class I<T>{" +
- " public void m(T t){};" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<T> extends I<T>{" +
- " public void m(T t){}; " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<T> extends I<T>{}");
- IApi fromApi = convert(C0, I);
- IApi toApi = convert(C1, I);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethodGeneric1() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public class I<T,S>{" +
- " public void m(S s){};" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<Q, R> extends I<Q,R>{" +
- " public void m(R t){}; " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<Y,Z> extends I<Y,Z>{}");
- IApi fromApi = convert(C0, I);
- IApi toApi = convert(C1, I);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethodGeneric2() throws IOException{
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public class I<T,S>{" +
- " public void m(S s){};" +
- "}");
- CompilationUnit J = new CompilationUnit("a.J",
- "package a; " +
- "public class J<W> extends I<Number,W>{" +
- " public void m(W w){};" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<Q> extends J<Q>{" +
- " public void m(Q t){}; " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<Y> extends J<Y>{}");
- IApi fromApi = convert(C0, I, J);
- IApi toApi = convert(C1, I, J);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
-
-
- @Test
- public void compareMissingInheritedMethodGeneric3() throws IOException{
- CompilationUnit Q = new CompilationUnit("a.Q",
- "package a; " +
- "public class Q<S,T>{ " +
- " public void m(T s){} " +
- "}");
-
- CompilationUnit W = new CompilationUnit("a.W",
- "package a; " +
- "public class W<A,B> extends Q<A,A>{}");
- CompilationUnit E0 = new CompilationUnit("a.E",
- "package a; " +
- "public class E<C,D> extends W<C,C>{" +
- " public void m(C s){}" +
- "}");
- CompilationUnit E1 = new CompilationUnit("a.E",
- "package a; " +
- "public class E<C,D> extends W<C,C>{}");
- IApi fromApi = convert(E0, Q, W);
- IApi toApi = convert(E1, Q, W);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethodGeneric4() throws IOException{
- CompilationUnit Q = new CompilationUnit("a.Q",
- "package a; " +
- "public class Q<S,T>{ " +
- " public void m(T t, S s){} " +
- "}");
-
- CompilationUnit W = new CompilationUnit("a.W",
- "package a; " +
- "public class W<A,B> extends Q<A,A>{}");
- CompilationUnit E0 = new CompilationUnit("a.E",
- "package a; " +
- "public class E<C,D> extends W<C,C>{" +
- " public void m(C s, C c){}" +
- "}");
- CompilationUnit E1 = new CompilationUnit("a.E",
- "package a; " +
- "public class E<C,D> extends W<C,C>{}");
- IApi fromApi = convert(E0, Q, W);
- IApi toApi = convert(E1, Q, W);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void compareMissingInheritedMethodGeneric5() throws IOException{
- CompilationUnit Q = new CompilationUnit("a.Q",
- "package a; " +
- "public class Q{}");
-
- CompilationUnit I = new CompilationUnit("a.I",
- "package a; " +
- "public class I<S,T>{" +
- " public void m(T s){};" +
- "}");
- CompilationUnit C0 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<P> extends I<P, Q>{" +
- " public void m(Q t){}; " +
- "}");
- CompilationUnit C1 = new CompilationUnit("a.C0",
- "package a; " +
- "public class C0<Y> extends I<Y, Q>{}");
- IApi fromApi = convert(C0, I, Q);
- IApi toApi = convert(C1, I, Q);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
-
- @Test
- public void substitutionTest() throws IOException{
- CompilationUnit NUMBER = new CompilationUnit("a.Number",
- "package a; " +
- "public class Number{}");
- CompilationUnit Q = new CompilationUnit("a.A",
- "package a; " +
- "public class A<T>{ " +
- " public void m(T t){} " +
- "}");
- CompilationUnit E0 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{" +
- " public void m(Number n){}" +
- "}");
- CompilationUnit E1 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{}");
- IApi fromApi = convert(E0, Q, NUMBER);
- IApi toApi = convert(E1, Q, NUMBER);
-
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void substitutionArrayTest() throws IOException{
- CompilationUnit NUMBER = new CompilationUnit("a.Number",
- "package a; " +
- "public class Number{}");
- CompilationUnit Q = new CompilationUnit("a.A",
- "package a; " +
- "public class A<T>{ " +
- " public void m(T[] t){} " +
- "}");
- CompilationUnit E0 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{" +
- " public void m(Number[] n){}" +
- "}");
- CompilationUnit E1 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{}");
- IApi fromApi = convert(E0, Q, NUMBER);
- IApi toApi = convert(E1, Q, NUMBER);
-
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-
- @Test
- public void substitutionNestedTypes() throws IOException{
- CompilationUnit NUMBER = new CompilationUnit("a.Number",
- "package a; " +
- "public class Number{}");
- CompilationUnit Q = new CompilationUnit("a.A",
- "package a; " +
- "public class A<T>{ " +
- " public void m(A<A<T[]>> t){} " +
- "}");
- CompilationUnit E0 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{" +
- " public void m(A<A<Number[]>> n){}" +
- "}");
- CompilationUnit E1 = new CompilationUnit("a.E",
- "package a; " +
- "public class E extends A<Number>{}");
- IApi fromApi = convert(E0, Q, NUMBER);
- IApi toApi = convert(E1, Q, NUMBER);
-
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNull(apiDelta);
- }
-}
diff --git a/tools/signature-tools/test/signature/comparator/PackageCompareTest.java b/tools/signature-tools/test/signature/comparator/PackageCompareTest.java
deleted file mode 100644
index d522186..0000000
--- a/tools/signature-tools/test/signature/comparator/PackageCompareTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-
-import signature.comparator.util.AbstractComparatorTest;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.DeltaType;
-import signature.compare.model.IPackageDelta;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-
-import java.io.IOException;
-
-public abstract class PackageCompareTest extends AbstractComparatorTest{
-
- @Test
- public void compareEqualPackageTest0() throws IOException{
- CompilationUnit from = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- IApi fromApi = convert(from);
- IApi toApi = convert(from);
- IApiDelta delta = compare(fromApi, toApi);
- assertNull(delta);
- }
-
- @Test
- public void compareEqualPackageTest1() throws IOException{
- CompilationUnit from0 = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit from1 = new CompilationUnit("a.b.A",
- "package a.b; " +
- "public class A {}");
- IApi fromApi = convert(from0, from1);
- IApi toApi = convert(from0, from1);
- assertNull(compare(fromApi, toApi));
- }
-
- @Test
- public void compareRemovedPackagePackageTest1() throws IOException{
- CompilationUnit packageA = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit packageB = new CompilationUnit("a.b.A",
- "package a.b; " +
- "public class A {}");
- IApi fromApi = convert(packageA, packageB);
- IApi toApi = convert(packageA);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
-
- assertEquals(1, apiDelta.getPackageDeltas().size());
- IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next();
- assertEquals(DeltaType.REMOVED, packageDelta.getType());
- }
-
- @Test
- public void compareAddedPackagePackageTest1() throws IOException{
- CompilationUnit packageA = new CompilationUnit("a.A",
- "package a; " +
- "public class A {}");
- CompilationUnit packageB = new CompilationUnit("a.b.A",
- "package a.b; " +
- "public class A {}");
- IApi fromApi = convert(packageA);
- IApi toApi = convert(packageA, packageB);
- IApiDelta apiDelta = compare(fromApi, toApi);
- assertNotNull(apiDelta);
-
- assertEquals(1, apiDelta.getPackageDeltas().size());
- IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next();
- assertEquals(DeltaType.ADDED, packageDelta.getType());
- }
-}
diff --git a/tools/signature-tools/test/signature/comparator/util/AbstractComparatorTest.java b/tools/signature-tools/test/signature/comparator/util/AbstractComparatorTest.java
deleted file mode 100644
index 6392dc9..0000000
--- a/tools/signature-tools/test/signature/comparator/util/AbstractComparatorTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.comparator.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Before;
-
-import signature.compare.ApiComparator;
-import signature.compare.IApiComparator;
-import signature.compare.model.IApiDelta;
-import signature.compare.model.IClassDefinitionDelta;
-import signature.compare.model.IPackageDelta;
-import signature.converter.util.AbstractConvertTest;
-import signature.model.IApi;
-public abstract class AbstractComparatorTest extends AbstractConvertTest{
-
- private IApiComparator comparator;
-
- @Before
- public void setupComparator() {
- comparator = new ApiComparator();
- }
-
- public IApiDelta compare(IApi from, IApi to){
- return comparator.compare(from, to);
- }
-
- public IPackageDelta getSinglePackageDelta(IApiDelta apiDelta){
- assertNotNull(apiDelta);
- assertEquals(1, apiDelta.getPackageDeltas().size());
- return apiDelta.getPackageDeltas().iterator().next();
- }
-
- public IClassDefinitionDelta getSingleClassDelta(IApiDelta apiDelta){
- IPackageDelta packageDelta = getSinglePackageDelta(apiDelta);
- assertEquals(1, packageDelta.getClassDeltas().size());
- return packageDelta.getClassDeltas().iterator().next();
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/AllDexTests.java b/tools/signature-tools/test/signature/converter/AllDexTests.java
deleted file mode 100644
index 84d26a8..0000000
--- a/tools/signature-tools/test/signature/converter/AllDexTests.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-import signature.converter.dex.DexTestConverter;
-import signature.converter.util.ITestSourceConverter;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllDexTests.ClassTest.class,
- AllDexTests.PackageTest.class,
- AllDexTests.AnnotationTest.class,
- AllDexTests.VisibilityTest.class,
- AllDexTests.WildcardTest.class,
- AllDexTests.EnumTest.class
-})
-public class AllDexTests {
- private static ITestSourceConverter newConverter(){
- return new DexTestConverter();
- }
-
- public static class ClassTest extends ConvertClassTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class AnnotationTest extends ConvertAnnotationTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class PackageTest extends ConvertPackageTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class VisibilityTest extends ConvertVisibilityTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class WildcardTest extends ConvertWildcardTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class EnumTest extends ConvertEnumTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-
- public static class ParameterizedTypeTest extends ConvertParameterizedTypeTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-}
-
diff --git a/tools/signature-tools/test/signature/converter/AllDocletTests.java b/tools/signature-tools/test/signature/converter/AllDocletTests.java
deleted file mode 100644
index 610917e..0000000
--- a/tools/signature-tools/test/signature/converter/AllDocletTests.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-import signature.converter.doclet.DocletTestConverter;
-import signature.converter.util.ITestSourceConverter;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllDocletTests.ClassTest.class,
- AllDocletTests.PackageTest.class,
- AllDocletTests.AnnotationTest.class,
- AllDocletTests.VisibilityTest.class,
- AllDocletTests.WildcardTest.class,
- AllDocletTests.EnumTest.class
-})
-public class AllDocletTests {
- private static ITestSourceConverter newConverter(){
- return new DocletTestConverter();
- }
-
- public static class ClassTest extends ConvertClassTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class AnnotationTest extends ConvertAnnotationTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class PackageTest extends ConvertPackageTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class VisibilityTest extends ConvertVisibilityTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class WildcardTest extends ConvertWildcardTest {
- @Override
- public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
- public static class EnumTest extends ConvertEnumTest {
- @Override public ITestSourceConverter createConverter() {
- return newConverter();
- }
- }
-}
-
diff --git a/tools/signature-tools/test/signature/converter/ConvertAnnotationTest.java b/tools/signature-tools/test/signature/converter/ConvertAnnotationTest.java
deleted file mode 100644
index f53f403..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertAnnotationTest.java
+++ /dev/null
@@ -1,761 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IAnnotation;
-import signature.model.IAnnotationField;
-import signature.model.IApi;
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IEnumConstant;
-import signature.model.IPackage;
-import signature.model.IPrimitiveType;
-import signature.model.ITypeReference;
-import signature.model.Kind;
-import signature.model.impl.SigClassReference;
-import signature.model.impl.SigPrimitiveType;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertAnnotationTest extends AbstractConvertTest {
-
- // Tests whether an annotation declaration element may be annotated with
- // the declared annotation.
- @Test
- public void convertAnnotationDefinition1() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.ToDo",
- "package a; " +
- "public @interface ToDo {" +
- " @ToDo(name=\"ToDo\")" +
- " String name() default \"nobody\";" +
- "}");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "ToDo");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- assertEquals(0, sigClass.getConstructors().size());
- assertEquals(0, sigClass.getMethods().size());
- assertEquals(0, sigClass.getFields().size());
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("name", field.getName());
- assertEquals("String", ((IClassReference)field.getType()).getClassDefinition().getName());
- assertEquals("nobody", field.getDefaultValue());
- Set<IAnnotation> annotations = field.getAnnotations();
- assertEquals(1, annotations.size());
- IAnnotation annotation = annotations.iterator().next();
- assertSame(sigClass, annotation.getType().getClassDefinition());
- // TODO TEST add additional assert for annotation.getElements()
- }
-
- // Tests whether an annotation declaration may be annotated with
- // the declared annotation.
- @Test
- public void convertAnnotationDefinition2() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.ToDo",
- "package a; " +
- "@ToDo\n" +
- "public @interface ToDo {" +
- " String name() default \"nobody\";" +
- "}");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "ToDo");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- assertEquals(0, sigClass.getConstructors().size());
- assertEquals(0, sigClass.getMethods().size());
- assertEquals(0, sigClass.getFields().size());
- Set<IAnnotation> annotations = sigClass.getAnnotations();
- assertEquals(1, annotations.size());
- IAnnotation annotation = annotations.iterator().next();
- assertSame(sigClass, ((SigClassReference)annotation.getType()).getClassDefinition());
- assertEquals(0, annotation.getElements().size());
- }
-
- @Test
- public void convertAnnotationDefinition3() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.ToDo",
- "package a; " +
- "public @interface ToDo {" +
- " String name() default \"nobody\";" +
- " int num() default 3;" +
- "}");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "ToDo");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- assertEquals(0, sigClass.getConstructors().size());
- assertEquals(0, sigClass.getMethods().size());
- assertEquals(0, sigClass.getFields().size());
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(2, annotationFields.size());
- IAnnotationField name = ModelUtil.getAnnotationField(sigClass, "name");
- IAnnotationField num = ModelUtil.getAnnotationField(sigClass, "num");
-
- assertEquals("name", name.getName());
- assertEquals("num", num.getName());
-
- assertEquals("nobody", name.getDefaultValue());
- assertEquals(3, num.getDefaultValue());
- }
-
-
- // tests whether default int value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsInt1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " int value() default 1;" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField annotationField = annotationFields.iterator().next();
- assertEquals("value", annotationField.getName());
- assertTrue(annotationField.getType() instanceof IPrimitiveType);
- IPrimitiveType annotationFieldType = (IPrimitiveType)annotationField.getType();
- assertSame(SigPrimitiveType.INT_TYPE, annotationFieldType);
-
- assertTrue(annotationField.getDefaultValue() instanceof Integer);
- Integer defaultValue = (Integer)annotationField.getDefaultValue();
- assertEquals(1, defaultValue.intValue());
- }
-
- // tests whether default int[] value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsInt2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " int[] value() default {};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(0, defaultValue.length);
- }
-
- // tests whether default int[] value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsInt3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " int[] value() default {1,2};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof Integer);
- Integer defaultValue0int = (Integer)defaultValue0;
- assertEquals(1, defaultValue0int.intValue());
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof Integer);
- Integer defaultValue1int = (Integer)defaultValue1;
- assertEquals(2, defaultValue1int.intValue());
- }
-
-
- // tests whether default double value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsDouble1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " double value() default 1;" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField annotationField = annotationFields.iterator().next();
- assertEquals("value", annotationField.getName());
- assertTrue(annotationField.getType() instanceof IPrimitiveType);
- IPrimitiveType annotationFieldType = (IPrimitiveType)annotationField.getType();
- assertSame(SigPrimitiveType.DOUBLE_TYPE, annotationFieldType);
-
-
- assertTrue(annotationField.getDefaultValue() instanceof Double);
- Double defaultValue = (Double)annotationField.getDefaultValue();
- assertEquals(1.0, defaultValue.doubleValue());
- }
-
- // tests whether default int[] value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsDouble2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " double[] value() default {};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(0, defaultValue.length);
- }
-
- // tests whether default int[] value has the correct type and defaultValue
- @Test
- public void testAnnotationDefaultsDouble3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " double[] value() default {1,2.5};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof Double);
- Double defaultValue0int = (Double)defaultValue0;
- assertEquals(1, defaultValue0int.doubleValue());
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof Double);
- Double defaultValue1int = (Double)defaultValue1;
- assertEquals(2.5, defaultValue1int.doubleValue());
- }
-
-
- // tests whether default enum value has the correct type
- @Test
- public void testAnnotationDefaultsEnum1() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " Kind value() default Kind.TWO;" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.Kind",
- "package a; " +
- "public enum Kind {" +
- " ONE, TWO, THREE" +
- "}");
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
- assertEquals("Kind", ((IClassReference)field.getType()).getClassDefinition().getName());
- assertTrue(field.getDefaultValue() instanceof IEnumConstant);
- IEnumConstant defaultValue = (IEnumConstant)field.getDefaultValue();
-// assertEquals(1, defaultValue.getOrdinal());
- assertEquals("TWO", defaultValue.getName());
-
- IClassDefinition enumClass = ModelUtil.getClass(sigPackage, "Kind");
- assertTrue(enumClass.getKind() == Kind.ENUM);
- IEnumConstant enumTWO = null;
- Set<IEnumConstant> enumConstants = enumClass.getEnumConstants();
- for(IEnumConstant c : enumConstants){
- if("TWO".equals(c.getName())) enumTWO = c;
- }
- assertSame(enumTWO, defaultValue);
- }
-
- // tests whether default enum value has the correct type
- @Test
- public void testAnnotationDefaultsEnum2() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " Kind[] value() default {};" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.Kind",
- "package a; " +
- "public enum Kind {" +
- " ONE, TWO, THREE" +
- "}");
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(0, defaultValue.length);
- }
-
- // tests whether default enum value has the correct type
- @Test
- public void testAnnotationDefaultsEnum3() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " Kind[] value() default {Kind.ONE,Kind.TWO};" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.Kind",
- "package a; " +
- "public enum Kind {" +
- " ONE, TWO, THREE" +
- "}");
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
-
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("value", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- IClassDefinition enumClass = ModelUtil.getClass(sigPackage, "Kind");
- assertTrue(enumClass.getKind() == Kind.ENUM);
- IEnumConstant enumONE = null;
- IEnumConstant enumTWO = null;
- Set<IEnumConstant> enumConstants = enumClass.getEnumConstants();
- for(IEnumConstant c : enumConstants){
- if("ONE".equals(c.getName())) enumONE = c;
- if("TWO".equals(c.getName())) enumTWO = c;
- }
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof IEnumConstant);
- IEnumConstant defaultValue0enum = (IEnumConstant)defaultValue0;
-// assertEquals(0, defaultValue0enum.getOrdinal());
- assertEquals("ONE", defaultValue0enum.getName());
- assertSame(enumONE, defaultValue0enum);
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof IEnumConstant);
- IEnumConstant defaultValue1enum = (IEnumConstant)defaultValue1;
-// assertEquals(1, defaultValue1enum.getOrdinal());
- assertEquals("TWO", defaultValue1enum.getName());
- assertSame(enumTWO, defaultValue1enum);
- }
-
-
- @Test
- public void testAnnotationDefaultsAnnotation1() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " AA aa() default @AA;" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.AA",
- "package a; " +
- "public @interface AA {}");
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("aa", field.getName());
- IClassReference fieldType = (IClassReference)field.getType();
- assertEquals("AA", fieldType.getClassDefinition().getName());
-
- IClassDefinition aaType = ModelUtil.getClass(sigPackage, "AA");
- assertTrue(aaType.getKind() == Kind.ANNOTATION);
- assertSame(aaType, fieldType.getClassDefinition());
-
- assertTrue(field.getDefaultValue() instanceof IAnnotation);
- IAnnotation defaultValue = (IAnnotation)field.getDefaultValue();
- assertEquals(0, defaultValue.getElements().size());
- assertSame(aaType, defaultValue.getType().getClassDefinition());
- }
-
- @Test
- public void testAnnotationDefaultsAnnotation2() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " AA[] aa() default {};" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.AA",
- "package a; " +
- "public @interface AA {}");
-
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("aa", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(0, defaultValue.length);
- }
-
- @Test
- public void testAnnotationDefaultsAnnotation3() throws IOException {
- CompilationUnit src1 = new CompilationUnit("a.A",
- "package a; " +
- "public @interface A {" +
- " AA[] aa() default {@AA,@AA};" +
- "}");
- CompilationUnit src2 = new CompilationUnit("a.AA",
- "package a; " +
- "public @interface AA {}");
-
- IApi api = convert(src1, src2);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("aa", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- IClassDefinition aaType = ModelUtil.getClass(sigPackage, "AA");
- assertTrue(aaType.getKind() == Kind.ANNOTATION);
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof IAnnotation);
- IAnnotation defaultValue0ann = (IAnnotation)defaultValue0;
- assertSame(aaType, defaultValue0ann.getType().getClassDefinition());
- assertEquals(0, defaultValue0ann.getElements().size());
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof IAnnotation);
- IAnnotation defaultValue1ann = (IAnnotation)defaultValue1;
- assertSame(aaType, defaultValue1ann.getType().getClassDefinition());
- assertEquals(0, defaultValue1ann.getElements().size());
- }
-
-
-
- @Test
- public void testAnnotationDefaultsString1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " String str() default \"xxx\";" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("str", field.getName());
-
- assertTrue(field.getType() instanceof IClassReference);
- assertEquals("String", ((IClassReference)field.getType()).getClassDefinition().getName());
-
- assertTrue(field.getDefaultValue() instanceof String);
- String defaultValue = (String)field.getDefaultValue();
- assertEquals("xxx", defaultValue);
- }
-
- @Test
- public void testAnnotationDefaultsString2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " String[] str() default {};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("str", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- Object defaultValue = field.getDefaultValue();
- assertTrue(defaultValue instanceof Object[]);
- assertSame(defaultValue.getClass(), Object[].class);
- assertEquals(0, ((Object[])defaultValue).length);
- }
-
- @Test
- public void testAnnotationDefaultsString3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " String[] str() default {\"ONE\", \"TWO\"};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertTrue(sigClass.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = sigClass.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("str", field.getName());
-
- assertTrue(field.getType() instanceof IArrayType);
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof String);
- String defaultValue0str = (String)defaultValue0;
- assertEquals("ONE", defaultValue0str);
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof String);
- String defaultValue1str = (String)defaultValue1;
- assertEquals("TWO", defaultValue1str);
- }
-
- @Test
- public void testAnnotationDefaultsClass1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " Class cc() default A.class;" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "A");
- assertTrue(aType.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = aType.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("cc", field.getName());
-
- assertTrue(field.getType() instanceof IClassReference);
- assertEquals("Class", ((IClassReference)field.getType()).getClassDefinition().getName());
- Object defaultValue = field.getDefaultValue();
- assertSame(aType, ((IClassReference)defaultValue).getClassDefinition());
- }
-
- @Test
- public void testAnnotationDefaultsClass2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " Class cc() default void.class;" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "A");
- assertTrue(aType.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = aType.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("cc", field.getName());
-
- assertTrue(field.getType() instanceof IClassReference);
- assertEquals("Class", ((IClassReference)field.getType()).getClassDefinition().getName());
-
- Object defaultValue = field.getDefaultValue();
- assertTrue(defaultValue instanceof IPrimitiveType);
- assertEquals("void", ((IPrimitiveType)defaultValue).getName());
- assertSame(SigPrimitiveType.VOID_TYPE, defaultValue);
- }
-
- @Test
- public void testAnnotationDefaultsClass3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " Class[] cc() default {};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "A");
- assertTrue(aType.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = aType.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("cc", field.getName());
-
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(0, defaultValue.length);
- }
-
- @Test
- public void testAnnotationDefaultsClass4() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public @interface A {" +
- " Class[] cc() default {A.class, void.class};" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "A");
- assertTrue(aType.getKind() == Kind.ANNOTATION);
- Set<IAnnotationField> annotationFields = aType.getAnnotationFields();
- assertEquals(1, annotationFields.size());
- IAnnotationField field = annotationFields.iterator().next();
- assertEquals("cc", field.getName());
-
- assertTrue(field.getDefaultValue() instanceof Object[]);
- assertSame(field.getDefaultValue().getClass(), Object[].class);
- Object[] defaultValue = (Object[])field.getDefaultValue();
- assertEquals(2, defaultValue.length);
-
- Object defaultValue0 = defaultValue[0];
- assertTrue(defaultValue0 instanceof ITypeReference);
- ITypeReference defaultValue0type = (ITypeReference)defaultValue0;
- assertSame(aType, ((IClassReference)defaultValue0type).getClassDefinition());
-
- Object defaultValue1 = defaultValue[1];
- assertTrue(defaultValue1 instanceof ITypeReference);
- assertTrue(defaultValue1 instanceof IPrimitiveType);
- IPrimitiveType defaultValue1type = (IPrimitiveType)defaultValue1;
- assertEquals("void", defaultValue1type.getName());
- assertSame(SigPrimitiveType.VOID_TYPE, defaultValue1type);
- }
-
- @Test
- public void testAnnotationRetentionRuntime() throws IOException {
- CompilationUnit retention = new CompilationUnit("java.lang.annotation.Retention",
- "package java.lang.annotation; " +
- "@Retention(RetentionPolicy.RUNTIME) " +
- //"@Target(ElementType.ANNOTATION_TYPE) " +
- "public @interface Retention { " +
- " RetentionPolicy value() default RetentionPolicy.CLASS; " +
- "}");
- CompilationUnit retentionPolicy = new CompilationUnit("java.lang.annotation.RetentionPolicy",
- "package java.lang.annotation; " +
- "public enum RetentionPolicy { " +
- " SOURCE," +
- " CLASS," +
- " RUNTIME" +
- "}");
- CompilationUnit anno = new CompilationUnit("a.A",
- "package a;" +
- "@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.SOURCE)" +
- "public @interface A{}");
- CompilationUnit cla = new CompilationUnit("a.B",
- "package a;" +
- "@A public class B{}");
- IApi api = convert(anno, cla, retention, retentionPolicy);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "B");
- assertTrue(aType.getAnnotations().isEmpty());
- }
-
- @Test
- public void testAnnotationRetentionClass() throws IOException {
- CompilationUnit retention = new CompilationUnit("java.lang.annotation.Retention",
- "package java.lang.annotation; " +
- "@Retention(RetentionPolicy.RUNTIME) " +
- //"@Target(ElementType.ANNOTATION_TYPE) " +
- "public @interface Retention { " +
- " RetentionPolicy value() default RetentionPolicy.CLASS; " +
- "}");
- CompilationUnit retentionPolicy = new CompilationUnit("java.lang.annotation.RetentionPolicy",
- "package java.lang.annotation; " +
- "public enum RetentionPolicy { " +
- " SOURCE," +
- " CLASS," +
- " RUNTIME" +
- "}");
- CompilationUnit anno = new CompilationUnit("a.A",
- "package a;" +
- "@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.CLASS)" +
- "public @interface A{}");
- CompilationUnit cla = new CompilationUnit("a.B",
- "package a;" +
- "@A public class B{}");
- IApi api = convert(anno, cla, retention, retentionPolicy);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition aType = ModelUtil.getClass(sigPackage, "B");
- assertEquals(1, aType.getAnnotations().size());
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/ConvertClassTest.java b/tools/signature-tools/test/signature/converter/ConvertClassTest.java
deleted file mode 100644
index 5bcdcb4..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertClassTest.java
+++ /dev/null
@@ -1,668 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IAnnotation;
-import signature.model.IApi;
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IField;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.IParameter;
-import signature.model.IParameterizedType;
-import signature.model.ITypeReference;
-import signature.model.ITypeVariableDefinition;
-import signature.model.ITypeVariableReference;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.impl.SigPrimitiveType;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertClassTest extends AbstractConvertTest {
-
- @Test
- public void convertPackageClassTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.b.A", "package a.b; public class A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a.b");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.b.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals("a.b", sigPackage.getName());
- assertEquals(1, sigPackage.getClasses().size());
- }
-
- @Test
- public void convertClassClassTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertClassInterfaceTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public interface A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.INTERFACE, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertClassEnumTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public enum A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.ENUM, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertClassAnnotationTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public @interface A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.ANNOTATION, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertAnnotationTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; @Deprecated public class A{}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- assertEquals(1, sigClass.getAnnotations().size());
- IAnnotation annotation = sigClass.getAnnotations().iterator().next();
- assertEquals("java.lang.Deprecated", annotation.getType().getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertAnnotationOnFieldTest() throws IOException {
- IApi api = convert(new CompilationUnit("a.A",
- "package a; " +
- "public class A{" +
- " @Deprecated" +
- " public int f;" +
- "}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- assertEquals(1, sigClass.getFields().size());
- IField field = sigClass.getFields().iterator().next();
- assertEquals("f", field.getName());
- assertEquals(1, field.getAnnotations().size());
- IAnnotation annotation = field.getAnnotations().iterator().next();
- assertEquals("java.lang.Deprecated", annotation.getType().getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertGenericClass0() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A<T> {}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- //test type variable
- assertEquals(1, sigClass.getTypeParameters().size());
- ITypeVariableDefinition variable = sigClass.getTypeParameters().get(0);
- assertEquals("T", variable.getName());
- //test type variable bound
- assertEquals(1, variable.getUpperBounds().size());
- IClassReference bound = (IClassReference) variable.getUpperBounds().get(0);
- assertEquals("java.lang.Object", bound.getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertGenericClass00() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A<T extends Integer> {}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- //test type variable
- assertEquals(1, sigClass.getTypeParameters().size());
- ITypeVariableDefinition variable = sigClass.getTypeParameters().get(0);
- assertEquals("T", variable.getName());
- //test type variable bound
- assertEquals(1, variable.getUpperBounds().size());
- IClassReference bound = (IClassReference) variable.getUpperBounds().get(0);
- assertEquals("java.lang.Integer", bound.getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertGenericClass1() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A<S,T> {}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- //test type variable
- assertEquals(2, sigClass.getTypeParameters().size());
- ITypeVariableDefinition variableS = sigClass.getTypeParameters().get(0);
- assertEquals("S", variableS.getName());
- //test type variable bound
- assertEquals(1, variableS.getUpperBounds().size());
- IClassReference boundS = (IClassReference) variableS.getUpperBounds().get(0);
- assertEquals("java.lang.Object", boundS.getClassDefinition().getQualifiedName());
-
- ITypeVariableDefinition variableT = sigClass.getTypeParameters().get(1);
- assertEquals("T", variableT.getName());
- //test type variable bound
- assertEquals(1, variableT.getUpperBounds().size());
- IClassReference boundT = (IClassReference) variableT.getUpperBounds().get(0);
- assertEquals("java.lang.Object", boundT.getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertGenericClass2() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A<S,T extends S> {}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
- //test type variable
- assertEquals(2, sigClass.getTypeParameters().size());
- ITypeVariableDefinition variableS = sigClass.getTypeParameters().get(0);
- assertEquals("S", variableS.getName());
- //test type variable bound
- assertEquals(1, variableS.getUpperBounds().size());
- IClassReference boundS = (IClassReference) variableS.getUpperBounds().get(0);
- assertEquals("java.lang.Object", boundS.getClassDefinition().getQualifiedName());
-
- ITypeVariableDefinition variableT = sigClass.getTypeParameters().get(1);
- assertEquals("T", variableT.getName());
- //test type variable bound
- assertEquals(1, variableT.getUpperBounds().size());
- ITypeVariableReference boundT = (ITypeVariableReference) variableT.getUpperBounds().get(0);
- assertSame(variableS, boundT.getTypeVariableDefinition());
- }
-
- @Test
- public void convertClassImplementsInterface0() throws IOException {
- IApi api = convert(new CompilationUnit("a.A", "package a; public class A implements Cloneable {}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
-
- assertEquals(1, sigClass.getInterfaces().size());
- IClassDefinition clonable = ((IClassReference) sigClass.getInterfaces().iterator().next()).getClassDefinition();
- assertEquals("java.lang.Cloneable", clonable.getQualifiedName());
- assertEquals(Kind.INTERFACE, clonable.getKind());
- }
-
- @Test
- public void convertClassImplementsInterface1() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A implements I {}");
- CompilationUnit interfaceSrc = new CompilationUnit("a.I", "package a; public interface I {}");
- IApi api = convert(classSrc, interfaceSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
-
- IClassDefinition sigInterface = ModelUtil.getClass(sigPackage, "I");
- assertEquals("a.I", sigInterface.getQualifiedName());
- assertEquals("I", sigInterface.getName());
- assertEquals(Kind.INTERFACE, sigInterface.getKind());
- assertTrue(sigInterface.getModifiers().contains(Modifier.PUBLIC));
-
- assertEquals(1, sigClass.getInterfaces().size());
- IClassReference interfaze = (IClassReference) sigClass.getInterfaces().iterator().next();
- assertEquals(Kind.INTERFACE, interfaze.getClassDefinition().getKind());
- assertSame(sigInterface, interfaze.getClassDefinition());
- }
-
- @Test
- public void convertClassImplementsGenericInterface0() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A implements I<String> {}");
- CompilationUnit interfaceSrc = new CompilationUnit("a.I", "package a; public interface I<T> {}");
- IApi api = convert(classSrc, interfaceSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
-
- IClassDefinition sigInterface = ModelUtil.getClass(sigPackage, "I");
- assertEquals("a.I", sigInterface.getQualifiedName());
- assertEquals("I", sigInterface.getName());
- assertEquals(Kind.INTERFACE, sigInterface.getKind());
- assertTrue(sigInterface.getModifiers().contains(Modifier.PUBLIC));
-
- assertEquals(1, sigClass.getInterfaces().size());
- IParameterizedType interfaze = (IParameterizedType) sigClass.getInterfaces().iterator().next();
- //compare raw type "I"
- assertSame(sigInterface, interfaze.getRawType().getClassDefinition());
- //test type argument string
- assertEquals(1, interfaze.getTypeArguments().size());
- IClassReference string = (IClassReference) interfaze.getTypeArguments().get(0);
- assertEquals("java.lang.String", string.getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertGenericClassImplementsGenericInterface() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A<T> implements I<T> {}");
- CompilationUnit interfaceSrc = new CompilationUnit("a.I", "package a; public interface I<T> {}");
- IApi api = convert(classSrc, interfaceSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals("a.A", sigClass.getQualifiedName());
- assertEquals("A", sigClass.getName());
- assertEquals(Kind.CLASS, sigClass.getKind());
- assertTrue(sigClass.getModifiers().contains(Modifier.PUBLIC));
-
- //get type variable from class
- assertEquals(1, sigClass.getTypeParameters().size());
- ITypeVariableDefinition classTypeVar = sigClass.getTypeParameters().get(0);
- assertEquals("T", classTypeVar.getName());
- assertSame(sigClass, classTypeVar.getGenericDeclaration());
-
- //inspect interface
- IClassDefinition sigInterface = ModelUtil.getClass(sigPackage, "I");
- assertEquals("a.I", sigInterface.getQualifiedName());
- assertEquals("I", sigInterface.getName());
- assertEquals(Kind.INTERFACE, sigInterface.getKind());
- assertTrue(sigInterface.getModifiers().contains(Modifier.PUBLIC));
-
- //get type variable from interface
- assertEquals(1, sigInterface.getTypeParameters().size());
- ITypeVariableDefinition interfaceTypeVar = sigInterface.getTypeParameters().get(0);
-
- //get implemented interface from A
- assertEquals(1, sigClass.getInterfaces().size());
- IParameterizedType interfaze = (IParameterizedType) sigClass.getInterfaces().iterator().next();
-
- //compare raw type "I"
- assertSame(sigInterface, interfaze.getRawType().getClassDefinition());
-
- //test if type variable of A is type argument of I
- assertEquals(1, interfaze.getTypeArguments().size());
- ITypeVariableReference argument = (ITypeVariableReference) interfaze.getTypeArguments().get(0);
- assertSame(sigClass, argument.getTypeVariableDefinition().getGenericDeclaration());
- assertEquals(classTypeVar, argument.getTypeVariableDefinition());
-
- //test that the two type parameters are not equal
- assertNotSame(classTypeVar, interfaceTypeVar);
- assertEquals(classTypeVar.getName(), interfaceTypeVar.getName());
- assertNotSame(classTypeVar.getGenericDeclaration(), interfaceTypeVar.getGenericDeclaration());
- }
-
- @Test
- public void convertConstructor0() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public A(){} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertConstructor1a() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public class B{ } }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A.B");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PUBLIC));
- }
-
- @Test
- public void convertConstructor1b() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { protected class B{ } }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A.B");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PROTECTED));
- }
-
- @Test
- public void convertConstructor2() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A {}");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getConstructors().size());
- }
-
- @Test
- public void convertConstructor3() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public class B { public B(){}} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A.B");
- assertEquals(1, sigClass.getConstructors().size());
- }
-
- @Test
- public void convertConstructorWithException() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public A() throws NullPointerException{} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PUBLIC));
- assertEquals(1, constructor.getExceptions().size());
- IClassReference exception = (IClassReference) constructor.getExceptions().iterator().next();
- assertEquals("java.lang.NullPointerException", exception.getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertConstructorWithParameter() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public A(String param){} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PUBLIC));
- assertEquals(1, constructor.getParameters().size());
- IParameter param = constructor.getParameters().get(0);
- assertEquals("java.lang.String", ((IClassReference)param.getType()).getClassDefinition().getQualifiedName());
- }
-
- @Test
- public void convertConstructorWithGenericParameter() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A<T> { public A(T param){} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getConstructors().size());
- IConstructor constructor = sigClass.getConstructors().iterator().next();
- assertTrue(constructor.getModifiers().contains(Modifier.PUBLIC));
- assertEquals(1, constructor.getParameters().size());
- IParameter param = constructor.getParameters().get(0);
- ITypeVariableDefinition paramType = ((ITypeVariableReference)param.getType()).getTypeVariableDefinition();
- assertEquals("T", paramType.getName());
- assertSame(sigClass, paramType.getGenericDeclaration());
- }
-
- @Test
- public void convertVoidMethod() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public void m(){} }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getMethods().size());
- IMethod method = sigClass.getMethods().iterator().next();
- assertTrue(method.getModifiers().contains(Modifier.PUBLIC));
- assertEquals("m", method.getName());
- assertSame(SigPrimitiveType.VOID_TYPE, method.getReturnType());
- }
-
- @Test
- public void convertArrayMethod() throws IOException {
- CompilationUnit classSrc = new CompilationUnit("a.A", "package a; public class A { public String[] m(){ return null; } }");
- IApi api = convert(classSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- assertEquals(1, sigClass.getMethods().size());
- IMethod method = sigClass.getMethods().iterator().next();
- assertTrue(method.getModifiers().contains(Modifier.PUBLIC));
- assertEquals("m", method.getName());
- IArrayType arrayType = (IArrayType) method.getReturnType();
- IClassDefinition clazz = ((IClassReference) arrayType.getComponentType()).getClassDefinition();
- assertEquals("java.lang.String", clazz.getQualifiedName());
- }
-
- @Test
- public void testParameterConformance1() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "import java.util.List;" +
- "public class A<T> {" +
- " public String[] a;" +
- " public String[] b;" +
- " public List<String> c;" +
- " public List<String> d;" +
- " public List<T> e;" +
- " public List<T> f;" +
- "}"
- ));
- IPackage p = ModelUtil.getPackage(api, "test");
- assertEquals("test", p.getName());
- IClassDefinition c = ModelUtil.getClass(p, "A");
- assertEquals("A", c.getName());
- assertEquals("test.A", c.getQualifiedName());
-
- Map<String, IField> fields = new HashMap<String, IField>();
- for(IField f : c.getFields()){
- fields.put(f.getName(), f);
- }
- assertSame(((IClassReference)((IArrayType)fields.get("a").getType()).getComponentType()).getClassDefinition(), ((IClassReference)((IArrayType)fields.get("b").getType()).getComponentType()).getClassDefinition());
- assertSame(((IParameterizedType)fields.get("c").getType()).getRawType().getClassDefinition(), ((IParameterizedType)fields.get("d").getType()).getRawType().getClassDefinition());
- assertSame(((IParameterizedType)fields.get("e").getType()).getRawType().getClassDefinition(), ((IParameterizedType)fields.get("f").getType()).getRawType().getClassDefinition());
-
- ITypeReference type = fields.get("f").getType();
- assertTrue(type instanceof IParameterizedType);
- ITypeReference typeArgument = ((IParameterizedType)type).getTypeArguments().get(0);
- ITypeVariableDefinition typeParameter = c.getTypeParameters().get(0);
- assertSame(((ITypeVariableReference)typeArgument).getTypeVariableDefinition(), typeParameter);
- }
-
- @Test
- public void testParameterConformance2() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public class A<T> {" +
- " public <T> T foo(T t){return null;}" +
- "}"
- ));
- IPackage p = ModelUtil.getPackage(api, "test");
- assertEquals("test", p.getName());
-
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- ITypeVariableDefinition t = sigClass.getTypeParameters().get(0);
-
- IMethod sigMethod = sigClass.getMethods().iterator().next();
- ITypeVariableDefinition t1 = sigMethod.getTypeParameters().get(0);
- IParameter param = sigMethod.getParameters().get(0);
- ITypeReference t2 = param.getType();
- ITypeReference t3 = sigMethod.getReturnType();
-
- assertSame(t1, ((ITypeVariableReference)t2).getTypeVariableDefinition());
- assertSame(((ITypeVariableReference)t2).getTypeVariableDefinition(), ((ITypeVariableReference)t3).getTypeVariableDefinition());
-
- assertNotSame(t, t1);
- }
-
- @Test
- public void testInnerReferenceToOuterTypeVariable() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public class A<T> {" +
- " public class B {" +
- " public T f;" +
- " } " +
- "}"
- ));
- IPackage p = ModelUtil.getPackage(api, "test");
- assertEquals("test", p.getName());
-
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- ITypeVariableDefinition t = sigClass.getTypeParameters().get(0);
-
- IClassDefinition innerClass = ModelUtil.getClass(sigPackage, "A.B");
- IField field = ModelUtil.getField(innerClass, "f");
-
- assertSame(t, ((ITypeVariableReference)field.getType()).getTypeVariableDefinition());
- }
-
-
- @Test
- public void convertTypeVariableMultipleUpperBound() throws IOException {
- String source =
- "package a; " +
- "public class A<T extends Comparable<T> & java.io.Serializable> {}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
-
- List<ITypeVariableDefinition> typeParameters = sigClass.getTypeParameters();
- assertEquals(1, typeParameters.size());
-
- ITypeVariableDefinition typeVariable = typeParameters.get(0);
- List<ITypeReference> upperBounds = typeVariable.getUpperBounds();
- assertEquals(2, upperBounds.size());
- ITypeReference firstBound = upperBounds.get(0);
- ITypeReference secondBound = upperBounds.get(1);
-
- assertTrue(firstBound instanceof IParameterizedType);
-
- IParameterizedType parametrizedType = (IParameterizedType)firstBound;
-
- IClassReference rawType = parametrizedType.getRawType();
- assertEquals("Comparable", rawType.getClassDefinition().getName());
- assertEquals(1, parametrizedType.getTypeArguments().size());
- ITypeVariableReference variable = (ITypeVariableReference) parametrizedType.getTypeArguments().get(0);
- assertSame(typeVariable, variable.getTypeVariableDefinition());
-
- assertTrue(secondBound instanceof IClassReference);
- IClassReference secondBoundClass = (IClassReference) secondBound;
- assertEquals("Serializable", secondBoundClass.getClassDefinition().getName());
- }
-
- @Test
- public void convertPrivateStaticInnerClass0() throws IOException {
- String source =
- "package a; " +
- "public class A { " +
- " private static class I{}" +
- " private transient Object i = new I(); " +
- "}";
- IApi api = convert(Visibility.PRIVATE, new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition innerClass = ModelUtil.getClass(sigPackage, "A.I");
- assertEquals("A.I", innerClass.getName());
- Set<IConstructor> constructors = innerClass.getConstructors();
- assertEquals(1, constructors.size());
- }
-
- @Test
- public void convertPrivateStaticInnerClass1() throws IOException {
- String source =
- "package a; " +
- "public class A {" +
- " private static class B {" +
- " public static class C {}" +
- " }" +
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(1, sigPackage.getClasses().size());
- }
-
- /**
- * Tests whether the first constructor argument is removed.
- */
- @Test
- public void convertNonStaticInnerClassConstructor0() throws IOException {
- String source =
- "package a; " +
- "public class A {" +
- " public class B {" +
- " public B(){}" +
- " }" +
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition innerClass = ModelUtil.getClass(sigPackage, "A.B");
- assertEquals(1, innerClass.getConstructors().size());
- Set<IConstructor> constructors = innerClass.getConstructors();
- IConstructor first = constructors.iterator().next();
- //implicit A.this reference must be removed
- assertEquals(0, first.getParameters().size());
- }
-
- /**
- * Tests whether the first constructor argument is removed.
- */
- @Test
- public void convertNonStaticInnerClassConstructor1() throws IOException {
- String source =
- "package a; " +
- "public class A {" +
- " public class B {}" +
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition innerClass = ModelUtil.getClass(sigPackage, "A.B");
- assertEquals(1, innerClass.getConstructors().size());
- Set<IConstructor> constructors = innerClass.getConstructors();
- IConstructor first = constructors.iterator().next();
- //implicit A.this reference must be removed
- assertEquals(0, first.getParameters().size());
- }
-
-
-
-}
diff --git a/tools/signature-tools/test/signature/converter/ConvertEnumTest.java b/tools/signature-tools/test/signature/converter/ConvertEnumTest.java
deleted file mode 100644
index 98ebd612..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertEnumTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-import signature.model.IArrayType;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IConstructor;
-import signature.model.IEnumConstant;
-import signature.model.IField;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.IParameter;
-import signature.model.Kind;
-import signature.model.Modifier;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertEnumTest extends AbstractConvertTest {
-
- @Test
- public void testEnum1() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public enum A {" +
- " ONE, TWO, THREE" +
- "}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition c = ModelUtil.getClass(sigPackage, "A");
- assertNotNull(c);
- assertTrue(c.getKind() == Kind.ENUM);
-
- Set<IEnumConstant> constants = c.getEnumConstants();
- assertEquals(3, constants.size());
-
- Set<String> constantNames = new HashSet<String>();
- for (IEnumConstant constant : constants) {
- constantNames.add(constant.getName());
- }
-
- assertTrue(constantNames.contains("ONE"));
- assertTrue(constantNames.contains("TWO"));
- assertTrue(constantNames.contains("THREE"));
-
-// IEnumConstant[] enumConstants = new IEnumConstant[3];
-// for (IEnumConstant enumConstant : constants) {
-// enumConstants[enumConstant.getOrdinal()] = enumConstant;
-// assertEquals(0, enumConstant.getAnnotations().size());
-// assertSame(c, enumConstant.getType());
-// }
-//
-// assertEquals("ONE", enumConstants[0].getName());
-// assertEquals("TWO", enumConstants[1].getName());
-// assertEquals("THREE", enumConstants[2].getName());
- }
-
- @Test
- public void testEnum2() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public enum A {" +
- " ONE, TWO, THREE;" +
- " public static A FOUR = ONE;" +
- "}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition c = ModelUtil.getClass(sigPackage, "A");
- assertNotNull(c);
- assertTrue(c.getKind() == Kind.ENUM);
-
- Set<IEnumConstant> constants = c.getEnumConstants();
- assertEquals(3, constants.size());
-
- Set<IField> fields = c.getFields();
- assertEquals(1, fields.size());
- IField field = c.getFields().iterator().next();
-
- assertEquals("FOUR", field.getName());
- assertSame(c, ((IClassReference)field.getType()).getClassDefinition());
- }
-
-
- @Test
- public void testEnum3() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public enum A {" +
- " ONE(1), TWO(2), THREE(3);" +
- " A(int value){}" +
- "}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition c = ModelUtil.getClass(sigPackage, "A");
- assertNotNull(c);
- assertTrue(c.getKind() == Kind.ENUM);
-
- Set<IEnumConstant> constants = c.getEnumConstants();
- assertEquals(3, constants.size());
-
- Set<IConstructor> ctors = c.getConstructors();
- assertEquals(0, ctors.size());
-
- Set<IMethod> methods = c.getMethods();
- assertEquals(2, methods.size());
- Map<String, IMethod> map = new HashMap<String, IMethod>();
- for(IMethod m : methods){
- map.put(m.getName(), m);
- }
-
- IMethod values = map.get("values");
- assertNotNull(values);
- assertEquals(0, values.getParameters().size());
- assertTrue(values.getReturnType() instanceof IArrayType);
- assertSame(c, ((IClassReference)((IArrayType)values.getReturnType()).getComponentType()).getClassDefinition());
- assertTrue(c.getModifiers().contains(Modifier.PUBLIC));
- assertFalse(c.getModifiers().contains(Modifier.STATIC));
- assertTrue(c.getModifiers().contains(Modifier.FINAL));
-
- IMethod valueOf = map.get("valueOf");
- assertNotNull(valueOf);
- assertEquals(1, valueOf.getParameters().size());
- IParameter param = valueOf.getParameters().iterator().next();
- assertEquals("java.lang.String", ((IClassReference)param.getType()).getClassDefinition().getQualifiedName());
- assertSame(c, ((IClassReference)valueOf.getReturnType()).getClassDefinition());
- }
-
- @Test
- public void testEnum4() throws IOException {
- IApi api = convert(new CompilationUnit("test.A",
- "package test; " +
- "public enum A {" +
- " ONE { void m(){} }, TWO{ void m(){} };" +
- " abstract void m();" +
- "}"));
- IPackage sigPackage = ModelUtil.getPackage(api, "test");
- IClassDefinition c = ModelUtil.getClass(sigPackage, "A");
- assertNotNull(c);
- assertTrue(c.getKind() == Kind.ENUM);
-
- Set<IEnumConstant> constants = c.getEnumConstants();
- assertEquals(2, constants.size());
-
- Set<IConstructor> ctors = c.getConstructors();
- assertEquals(0, ctors.size());
-
- Set<IMethod> methods = c.getMethods();
- assertEquals(2, methods.size());
- Map<String, IMethod> map = new HashMap<String, IMethod>();
- for(IMethod m : methods){
- map.put(m.getName(), m);
- }
-
- IMethod values = map.get("values");
- assertNotNull(values);
- assertEquals(0, values.getParameters().size());
- assertTrue(values.getReturnType() instanceof IArrayType);
- assertSame(c, ((IClassReference)((IArrayType)values.getReturnType()).getComponentType()).getClassDefinition());
- assertTrue(c.getModifiers().contains(Modifier.PUBLIC));
- assertFalse(c.getModifiers().contains(Modifier.STATIC));
- assertFalse(c.getModifiers().contains(Modifier.FINAL));
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/ConvertPackageTest.java b/tools/signature-tools/test/signature/converter/ConvertPackageTest.java
deleted file mode 100644
index edd2a41..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertPackageTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IAnnotation;
-import signature.model.IApi;
-import signature.model.IPackage;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertPackageTest extends AbstractConvertTest {
-
- // tests whether package annotations are returned
- @Test
- public void testPackageAnnotation() throws IOException {
- CompilationUnit packageSrc = new CompilationUnit("a.package-info", "@Deprecated package a;");
- CompilationUnit classSrc = new CompilationUnit("a.X", "package a; public class X{}");
- IApi api = convert(classSrc, packageSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(1, sigPackage.getAnnotations().size());
- IAnnotation annotation = sigPackage.getAnnotations().iterator().next();
- assertEquals("java.lang.Deprecated", annotation.getType().getClassDefinition().getQualifiedName());
- }
-
- // tests that package-info is not returned as class
- @Test
- public void testNumberOfClasses1() throws IOException {
- CompilationUnit packageSrc = new CompilationUnit("a.package-info", "@Deprecated package a;");
- CompilationUnit classSrc = new CompilationUnit("a.X", "package a; public class X{}");
- IApi api = convert(classSrc, packageSrc);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(1, sigPackage.getClasses().size());
- }
-
- // tests that nested classes are returned as package classes
- @Test
- public void testNumberOfClasses2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.X",
- "package a;" +
- "public class X{" +
- " public static class Y{}" +
- "}");
- IApi api = convert(src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(2, sigPackage.getClasses().size());
- }
-
-}
\ No newline at end of file
diff --git a/tools/signature-tools/test/signature/converter/ConvertParameterizedTypeTest.java b/tools/signature-tools/test/signature/converter/ConvertParameterizedTypeTest.java
deleted file mode 100644
index 653d42f..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertParameterizedTypeTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-import signature.model.IClassDefinition;
-import signature.model.IField;
-import signature.model.IPackage;
-import signature.model.IParameterizedType;
-import signature.model.ITypeReference;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertParameterizedTypeTest extends AbstractConvertTest {
- /**
- * [L, a, /, A, $, B, <, L, j, a, v, a, /, l, a, n, g, /, I, n, t, e, g, e, r, ;, >, ;]
- * '$' - separated
- * @throws IOException
- */
- @Test
- public void convertParameterizedType() throws IOException {
- String source =
- "package a; " +
- "public class A{" +
- " public class B<T> {} " +
- " public A.B<Integer> f; "+
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- IField field = ModelUtil.getField(sigClass, "f");
-
- ITypeReference type = field.getType();
- assertTrue(type instanceof IParameterizedType);
-
- IParameterizedType parametrizedType = (IParameterizedType)type;
- ITypeReference ownerType = parametrizedType.getOwnerType();
- assertNotNull(ownerType);
- }
-
- @Test
- public void convertWildcardLowerBound() throws IOException {
- String clazz =
- "package a; " +
- "public final class A<T> implements I<T>{ " +
- " abstract class Super{} " +
- " final class Sub extends Super implements I<T>{} " +
- "}";
- String interfaze =
- "package a; " +
- "public interface I <T>{}";
- IApi api = convert(Visibility.PRIVATE, new CompilationUnit("a.A", clazz),new CompilationUnit("a.I", interfaze));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A.Sub");
- System.out.println(sigClass);
- }
-
- public class A{
- public class B<T> {}
- public A.B<Integer> f;
- }
-
- @Test
- public void reflectionTest0() throws SecurityException, NoSuchFieldException{
- Field field = A.class.getDeclaredField("f");
- ParameterizedType paramType = (ParameterizedType)field.getGenericType();
- assertNotNull(paramType.getOwnerType());
- }
-
- public static class C<T>{}
-
- ConvertParameterizedTypeTest.C<String> f;
-
- @Test
- public void reflectionTest1() throws SecurityException, NoSuchFieldException{
- Field field = ConvertParameterizedTypeTest.class.getDeclaredField("f");
- ParameterizedType paramType = (ParameterizedType)field.getGenericType();
- assertNotNull(paramType.getOwnerType());
- }
-
- public static class E<T>{
- static class F<Q>{}
- E.F<String> f;
- }
-
-
- @Test
- public void reflectionTest2() throws SecurityException, NoSuchFieldException {
- Field field = E.class.getDeclaredField("f");
- ParameterizedType paramType = (ParameterizedType) field.getGenericType();
- assertNotNull(paramType.getOwnerType());
- }
-}
diff --git a/tools/signature-tools/test/signature/converter/ConvertVisibilityTest.java b/tools/signature-tools/test/signature/converter/ConvertVisibilityTest.java
deleted file mode 100644
index 09fc32f..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertVisibilityTest.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.junit.Test;
-
-import signature.converter.Visibility;
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-import signature.model.IClassDefinition;
-import signature.model.IMethod;
-import signature.model.IPackage;
-import signature.model.util.ModelUtil;
-
-public abstract class ConvertVisibilityTest extends AbstractConvertTest {
-
- @Test
- public void testVisibilityMethods1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public class A{" +
- " public void foo1(){}" +
- " protected void foo2(){}" +
- " void foo3(){}" +
- " private void foo4(){}" +
- "}");
-
- IApi api = convert(Visibility.PUBLIC, src);
- IPackage p = ModelUtil.getPackage(api, "a");
- IClassDefinition c = ModelUtil.getClass(p, "A");
- Set<IMethod> methods = c.getMethods();
- assertEquals(1, methods.size());
- }
-
- @Test
- public void testVisibilityMethods2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public class A{" +
- " public void foo1(){}" +
- " protected void foo2(){}" +
- " void foo3(){}" +
- " private void foo4(){}" +
- "}");
-
- IApi api = convert(Visibility.PROTECTED, src);
- IPackage p = ModelUtil.getPackage(api, "a");
- IClassDefinition c = ModelUtil.getClass(p, "A");
- Set<IMethod> methods = c.getMethods();
- assertEquals(2, methods.size());
- }
-
- @Test
- public void testVisibilityMethods3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public class A{" +
- " public void foo1(){}" +
- " protected void foo2(){}" +
- " void foo3(){}" +
- " private void foo4(){}" +
- "}");
-
- IApi api = convert(Visibility.PACKAGE, src);
- IPackage p = ModelUtil.getPackage(api, "a");
- IClassDefinition c = ModelUtil.getClass(p, "A");
- Set<IMethod> methods = c.getMethods();
- assertEquals(3, methods.size());
- }
-
- @Test
- public void testVisibilityMethods4() throws IOException {
- CompilationUnit src = new CompilationUnit("a.A",
- "package a;" +
- "public class A{" +
- " public void foo1(){}" +
- " protected void foo2(){}" +
- " void foo3(){}" +
- " private void foo4(){}" +
- "}");
-
- IApi api = convert(Visibility.PRIVATE, src);
- IPackage p = ModelUtil.getPackage(api, "a");
- IClassDefinition c = ModelUtil.getClass(p, "A");
- Set<IMethod> methods = c.getMethods();
- assertEquals(4, methods.size());
- }
-
- @Test
- public void testVisibility1() throws IOException {
- CompilationUnit src = new CompilationUnit("a.X1",
- "package a;" +
- "public class X1{" +
- " static class X2{}" +
- " protected static class X3{}" +
- " private static class X4{}" +
- "}");
-
- IApi api = convert(Visibility.PUBLIC, src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(1, sigPackage.getClasses().size());
- }
-
- @Test
- public void testVisibility2() throws IOException {
- CompilationUnit src = new CompilationUnit("a.X1",
- "package a;" +
- "public class X1{" +
- " static class X2{}" +
- " protected static class X3{}" +
- " private static class X4{}" +
- "}");
-
- IApi api = convert(Visibility.PROTECTED, src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(2, sigPackage.getClasses().size());
- assertNotNull(ModelUtil.getClass(sigPackage, "X1.X3"));
- }
-
- @Test
- public void testVisibility3() throws IOException {
- CompilationUnit src = new CompilationUnit("a.X1",
- "package a;" +
- "public class X1{" +
- " static class X2{}" +
- " protected static class X3{}" +
- " private static class X4{}" +
- "}");
-
- IApi api = convert(Visibility.PACKAGE, src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(3, sigPackage.getClasses().size());
- assertNotNull(ModelUtil.getClass(sigPackage, "X1.X2"));
- }
-
- @Test
- public void testVisibility4() throws IOException {
- CompilationUnit src = new CompilationUnit("a.X1",
- "package a;" +
- "public class X1{" +
- " static class X2{}" +
- " protected static class X3{}" +
- " private static class X4{}" +
- "}");
-
- IApi api = convert(Visibility.PRIVATE, src);
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- assertEquals(4, sigPackage.getClasses().size());
- assertNotNull(ModelUtil.getClass(sigPackage, "X1.X4"));
- }
-
-}
\ No newline at end of file
diff --git a/tools/signature-tools/test/signature/converter/ConvertWildcardTest.java b/tools/signature-tools/test/signature/converter/ConvertWildcardTest.java
deleted file mode 100644
index d18c568..0000000
--- a/tools/signature-tools/test/signature/converter/ConvertWildcardTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import signature.converter.util.AbstractConvertTest;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-import signature.model.IClassDefinition;
-import signature.model.IClassReference;
-import signature.model.IField;
-import signature.model.IPackage;
-import signature.model.IParameterizedType;
-import signature.model.ITypeReference;
-import signature.model.IWildcardType;
-import signature.model.util.ModelUtil;
-
-import java.io.IOException;
-
-public abstract class ConvertWildcardTest extends AbstractConvertTest {
-
- @Test
- public void convertWildcardUpperBound() throws IOException {
- String source =
- "package a; " +
- "public class A{" +
- " public java.util.Set<? extends Number> f; "+
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- IField field = ModelUtil.getField(sigClass, "f");
-
- ITypeReference type = field.getType();
- assertTrue(type instanceof IParameterizedType);
-
- IParameterizedType parametrizedType = (IParameterizedType)type;
-
- IClassDefinition rawType = parametrizedType.getRawType().getClassDefinition();
- assertEquals("Set", rawType.getName());
-
- assertEquals(1, parametrizedType.getTypeArguments().size());
- IWildcardType wildcardType = (IWildcardType) parametrizedType.getTypeArguments().get(0);
- assertEquals(1, wildcardType.getUpperBounds().size());
- ITypeReference upperBound = wildcardType.getUpperBounds().get(0);
- assertTrue(upperBound instanceof IClassReference);
-
- assertEquals("Number", ((IClassReference)upperBound).getClassDefinition().getName());
- }
-
- @Test
- public void convertWildcardLowerBound() throws IOException {
- String source =
- "package a; " +
- "public class A{" +
- " public java.util.Set<? super Number> f; "+
- "}";
- IApi api = convert(new CompilationUnit("a.A", source));
- IPackage sigPackage = ModelUtil.getPackage(api, "a");
- IClassDefinition sigClass = ModelUtil.getClass(sigPackage, "A");
- IField field = ModelUtil.getField(sigClass, "f");
-
- ITypeReference type = field.getType();
- assertTrue(type instanceof IParameterizedType);
-
- IParameterizedType parametrizedType = (IParameterizedType)type;
-
- IClassDefinition rawType = parametrizedType.getRawType().getClassDefinition();
- assertEquals("Set", rawType.getName());
-
- assertEquals(1, parametrizedType.getTypeArguments().size());
- IWildcardType wildcardType = (IWildcardType) parametrizedType.getTypeArguments().get(0);
- assertEquals(1, wildcardType.getUpperBounds().size());
- ITypeReference upperBound = wildcardType.getUpperBounds().get(0);
- assertTrue(upperBound instanceof IClassReference);
- assertEquals("Object", ((IClassReference)upperBound).getClassDefinition().getName());
-
- ITypeReference lowerBound = wildcardType.getLowerBound();
- assertTrue(lowerBound instanceof IClassReference);
- assertEquals("Number", ((IClassReference)lowerBound).getClassDefinition().getName());
- }
-}
diff --git a/tools/signature-tools/test/signature/converter/dex/DexExternalizerTest.java b/tools/signature-tools/test/signature/converter/dex/DexExternalizerTest.java
deleted file mode 100644
index 8e27da5..0000000
--- a/tools/signature-tools/test/signature/converter/dex/DexExternalizerTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import org.junit.Test;
-
-import signature.converter.Visibility;
-import signature.io.IApiExternalizer;
-import signature.io.impl.BinaryApi;
-import signature.model.IApi;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashSet;
-
-public class DexExternalizerTest {
-
- @Test
- public void testExternalizer() throws IOException{
- DexToSigConverter converter = new DexToSigConverter();
- IApi api = converter.convertApi("Dex Tests", DexUtil.getDexFiles(new HashSet<String>(Arrays.asList(new String[]{"resources/javaCore.dex"}))), Visibility.PRIVATE);
- System.setProperty("sun.io.serialization.extendedDebugInfo", "true");
- IApiExternalizer externalizer = new BinaryApi();
- externalizer.externalizeApi("dex-spec", api);
- }
-}
diff --git a/tools/signature-tools/test/signature/converter/dex/DexTestConverter.java b/tools/signature-tools/test/signature/converter/dex/DexTestConverter.java
deleted file mode 100644
index b6b90fa..0000000
--- a/tools/signature-tools/test/signature/converter/dex/DexTestConverter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import dex.reader.util.JavaSource;
-import dex.reader.util.JavaSourceToDexUtil;
-import dex.structure.DexFile;
-import signature.converter.Visibility;
-import signature.converter.dex.DexToSigConverter;
-import signature.converter.util.AbstractTestSourceConverter;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class DexTestConverter extends AbstractTestSourceConverter {
-
- public IApi convert(Visibility visibility, Set<CompilationUnit> units) throws IOException {
- JavaSourceToDexUtil toDexUtil = new JavaSourceToDexUtil();
- DexToSigConverter converter = new DexToSigConverter();
- Set<JavaSource> sources = new HashSet<JavaSource>();
- for (CompilationUnit unit : units) {
- sources.add(new JavaSource(unit.getName(), unit.getSource()));
- }
- DexFile dexFile = toDexUtil.getAllFrom(sources);
- return converter.convertApi("Dex Tests", Collections.singleton(dexFile), visibility);
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/dex/DexUtilTest.java b/tools/signature-tools/test/signature/converter/dex/DexUtilTest.java
deleted file mode 100644
index ff005fb..0000000
--- a/tools/signature-tools/test/signature/converter/dex/DexUtilTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-
-import dex.reader.DexTestsCommon;
-import dex.reader.util.JavaSource;
-import dex.reader.util.JavaSourceToDexUtil;
-import dex.structure.DexClass;
-import dex.structure.DexFile;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import signature.converter.dex.DexToSigConverter;
-import signature.model.impl.SigPackage;
-import static signature.converter.dex.DexUtil.*;
-
-import java.io.IOException;
-
-import static org.junit.Assert.*;
-
-public class DexUtilTest extends DexTestsCommon {
-
- private JavaSourceToDexUtil dexUtil;
- private DexToSigConverter converter;
-
- @Before
- public void setupDexUtil(){
- dexUtil = new JavaSourceToDexUtil();
- converter = new DexToSigConverter();
- }
-
- @Test
- public void convertPackageTest(){
- SigPackage aPackage = converter.convertPackage("a");
- assertEquals("a", aPackage.getName());
-
- aPackage = converter.convertPackage("a.b.c");
- assertEquals("a.b.c", aPackage.getName());
- }
-
- @Test
- public void getPackageNameTest(){
- assertEquals("",getPackageName("LA;"));
- assertEquals("a",getPackageName("La/A;"));
- assertEquals("a.b.c",getPackageName("La/b/c/A;"));
- }
-
- @Test
- public void getClassNameTest(){
- assertEquals("A",getClassName("LA;"));
- assertEquals("A",getClassName("La/A;"));
- assertEquals("A",getClassName("La/b/c/A;"));
- }
-
- @Test
- public void hasGenericSignatureTest() throws IOException {
- DexFile dexFile = dexUtil.getFrom(new JavaSource("A", "public class A{}"));
- DexClass dexClass = getClass(dexFile, "LA;");
- assertFalse(hasGenericSignature(dexClass));
-
- dexFile = dexUtil.getFrom(new JavaSource("B", "public class B<T>{}"));
- dexClass = getClass(dexFile, "LB;");
- assertTrue(hasGenericSignature(dexClass));
- }
-
- @Test
- public void getGenericSignatureTest() throws IOException {
- DexFile dexFile = dexUtil.getFrom(new JavaSource("A", "public class A{}"));
- DexClass dexClass = getClass(dexFile, "LA;");
- assertNull(getGenericSignature(dexClass));
-
- dexFile = dexUtil.getFrom(new JavaSource("B", "public class B<T>{}"));
- dexClass = getClass(dexFile, "LB;");
- assertEquals("<T:Ljava/lang/Object;>Ljava/lang/Object;", getGenericSignature(dexClass));
- }
-
-
-
-}
diff --git a/tools/signature-tools/test/signature/converter/dex/GenericSignatureParserTest.java b/tools/signature-tools/test/signature/converter/dex/GenericSignatureParserTest.java
deleted file mode 100644
index 52d73f8..0000000
--- a/tools/signature-tools/test/signature/converter/dex/GenericSignatureParserTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.dex;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import dex.reader.DexTestsCommon;
-import dex.reader.util.JavaSource;
-import dex.reader.util.JavaSourceToDexUtil;
-import dex.structure.DexClass;
-import dex.structure.DexFile;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import signature.converter.dex.DexToSigConverter;
-import signature.converter.dex.DexUtil;
-import signature.converter.dex.GenericSignatureParser;
-import signature.model.impl.SigClassDefinition;
-import signature.model.util.TypePool;
-
-import java.io.IOException;
-
-public class GenericSignatureParserTest extends DexTestsCommon{
-
- private DexToSigConverter converter;
- private JavaSourceToDexUtil dexUtil;
- private GenericSignatureParser parser;
-
- @Before
- public void setupConverter(){
- converter = new DexToSigConverter();
- dexUtil = new JavaSourceToDexUtil();
- parser = new GenericSignatureParser(new TypePool(), converter);
- }
-
- @Test
- public void getGenericSignatureTest() throws IOException {
- DexFile dexFile = dexUtil.getFrom(new JavaSource("B", "public class B<T>{}"));
- DexClass dexClass = getClass(dexFile, "LB;");
- assertEquals("<T:Ljava/lang/Object;>Ljava/lang/Object;", DexUtil.getGenericSignature(dexClass));
- SigClassDefinition sigClass = converter.convertClass(dexClass);
-
- parser.parseForClass(sigClass, DexUtil.getGenericSignature(dexClass));
- //type parameter name
- assertEquals(1, parser.formalTypeParameters.size());
- assertEquals("T", parser.formalTypeParameters.get(0).getName());
- //type parameter declaration
- assertSame(sigClass, parser.formalTypeParameters.get(0).getGenericDeclaration());
- //type parameter upper bounds
- assertEquals(1, parser.formalTypeParameters.get(0).getUpperBounds().size());
-// IType type = parser.formalTypeParameters.get(0).getUpperBounds().get(0);
-
- }
-}
diff --git a/tools/signature-tools/test/signature/converter/doclet/DocletTestConverter.java b/tools/signature-tools/test/signature/converter/doclet/DocletTestConverter.java
deleted file mode 100644
index 8e867ddb..0000000
--- a/tools/signature-tools/test/signature/converter/doclet/DocletTestConverter.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.doclet;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.reflect.Constructor;
-import java.util.HashSet;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.converter.doclet.DocletToSigConverter;
-import signature.converter.util.CompilationUnit;
-import signature.model.IApi;
-import signature.model.util.ModelUtil;
-
-import com.sun.javadoc.RootDoc;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Options;
-import com.sun.tools.javadoc.JavadocTool;
-import com.sun.tools.javadoc.Messager;
-import com.sun.tools.javadoc.ModifierFilter;
-import com.sun.tools.javadoc.RootDocImpl;
-
-public class DocletTestConverter extends signature.converter.util.AbstractTestSourceConverter {
-
- static String sourcepath;
- static String separator;
-
- static {
- separator = System.getProperty("file.separator");
-
- sourcepath = System.getProperty("java.io.tmpdir");
- sourcepath = sourcepath + separator + "cts" + separator;
- System.out.println(">> "+sourcepath);
- }
-
- public IApi convert(Visibility visibility, Set<CompilationUnit> units) throws IOException {
- try {
- Set<String> packages = new HashSet<String>();
- for(CompilationUnit u : units){
- putSource(u);
- String p = ModelUtil.getPackageName(u.getName());
- assert p.length() > 0 : "default package not supported by doclets";
- packages.add(p);
- }
-
- RootDoc root = getRootDoc(visibility, packages);
-
- DocletToSigConverter converter = new DocletToSigConverter();
-
- IApi api = converter.convertDocletRoot("Doclet Test", root, visibility, packages);
- return api;
- }
- finally {
- removeSources();
- }
- }
-
- public static void putSource(CompilationUnit source) throws IOException {
- String directory = sourcepath;
- String filename = source.getName(); // a.b.C
- int pos = filename.indexOf(".");
- while(pos > 0) {
- directory = directory + filename.substring(0, pos) + separator;
- filename = filename.substring(pos+1);
- pos = filename.indexOf(".");
- }
-
- File file = new File(directory, filename + ".java");
- File parent = file.getParentFile();
- parent.mkdirs();
-
- FileWriter wr = new FileWriter(file);
- wr.write(source.getSource());
- wr.close();
- }
-
- private static void removeSources() {
- File file = new File(sourcepath);
- removeFile(file);
- }
-
- private static void removeFile(File file){
- if(file.isDirectory()){
- for(File f : file.listFiles()) removeFile(f);
- }
- file.delete();
- }
-
- private static RootDoc getRootDoc(Visibility visibility, java.util.Set<String> packages) throws IOException {
- long accessModifier = 0;
- if(visibility == Visibility.PUBLIC){
- accessModifier =
- com.sun.tools.javac.code.Flags.PUBLIC; // 0x1
- }
- if(visibility == Visibility.PROTECTED){
- accessModifier =
- com.sun.tools.javac.code.Flags.PUBLIC // 0x1
- | com.sun.tools.javac.code.Flags.PROTECTED; // 0x4
- }
- if(visibility == Visibility.PACKAGE){
- accessModifier =
- com.sun.tools.javac.code.Flags.PUBLIC // 0x1
- | com.sun.tools.javac.code.Flags.PROTECTED // 0x4
- | com.sun.tools.javadoc.ModifierFilter.PACKAGE; // 0x80000000
- }
- if(visibility == Visibility.PRIVATE){
- accessModifier =
- com.sun.tools.javac.code.Flags.PUBLIC // 0x1
- | com.sun.tools.javac.code.Flags.PROTECTED // 0x4
- | com.sun.tools.javadoc.ModifierFilter.PACKAGE // 0x80000000
- | com.sun.tools.javac.code.Flags.PRIVATE; // 0x2
- }
-
- ModifierFilter showAccess = new ModifierFilter(accessModifier);
- boolean breakiterator = false;
- boolean quiet = false;
- boolean legacy = false;
- boolean docClasses = false;
-
- String docLocale = "";
- String encoding = null;
- ListBuffer<String> javaNames = new ListBuffer<String>();
- for(String p : packages)
- javaNames.append(p);
-
- ListBuffer<String[]> options = new ListBuffer<String[]>();
-
-
-// String sourcepath = "//D:/Documents/Projects/08_CTS/signature-tools/signature-tools/test/";
- options.append(new String[]{"-sourcepath", sourcepath});
-
- ListBuffer<String> subPackages = new ListBuffer<String>();
- ListBuffer<String> excludedPackages = new ListBuffer<String>();
-
- Context context = new Context();
- Options compOpts = Options.instance(context);
- compOpts.put("-sourcepath", sourcepath);
-
- Constructor<Messager> c;
- try {
-// c = Messager.class.getDeclaredConstructor(Context.class, String.class);
-// c.setAccessible(true);
-// c.newInstance(context, "SigTest");
- c = Messager.class.getDeclaredConstructor(Context.class, String.class, PrintWriter.class, PrintWriter.class, PrintWriter.class);
- c.setAccessible(true);
- PrintWriter err = new PrintWriter(new StringWriter());
- PrintWriter warn = new PrintWriter(new StringWriter());
- PrintWriter notice = new PrintWriter(new StringWriter());
- c.newInstance(context, "SigTest", err, warn, notice);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- JavadocTool comp = JavadocTool.make0(context);
- RootDocImpl root = comp.getRootDocImpl(docLocale, encoding, showAccess,
- javaNames.toList(), options.toList(), breakiterator,
- subPackages.toList(), excludedPackages.toList(), docClasses,
- legacy, quiet);
- return root;
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/util/AbstractConvertTest.java b/tools/signature-tools/test/signature/converter/util/AbstractConvertTest.java
deleted file mode 100644
index 04935d8..0000000
--- a/tools/signature-tools/test/signature/converter/util/AbstractConvertTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.util;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.junit.Before;
-
-import signature.converter.Visibility;
-import signature.model.IApi;
-
-public abstract class AbstractConvertTest extends AbstractTestSourceConverter {
-
- private ITestSourceConverter converter;
-
- /**
- * Creates and returns a converter instance.
- * @return a converter instance
- */
- public abstract ITestSourceConverter createConverter();
-
-
- @Before
- public void setupConverter(){
- converter = createConverter();
- }
-
- public IApi convert(Visibility visibility, Set<CompilationUnit> units) throws IOException {
- return converter.convert(visibility, units);
- }
-
-}
diff --git a/tools/signature-tools/test/signature/converter/util/AbstractTestSourceConverter.java b/tools/signature-tools/test/signature/converter/util/AbstractTestSourceConverter.java
deleted file mode 100644
index 5ca7422f..0000000
--- a/tools/signature-tools/test/signature/converter/util/AbstractTestSourceConverter.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.util;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IApi;
-
-public abstract class AbstractTestSourceConverter implements ITestSourceConverter {
-
- public IApi convert(Set<CompilationUnit> units) throws IOException {
- return convert(Visibility.PROTECTED, units);
- }
- public IApi convert(CompilationUnit... units) throws IOException {
- return convert(Visibility.PROTECTED, new HashSet<CompilationUnit>(Arrays.asList(units)));
- }
- public IApi convert(Visibility visibility, CompilationUnit... units) throws IOException {
- return convert(visibility, new HashSet<CompilationUnit>(Arrays.asList(units)));
- }
-}
-
diff --git a/tools/signature-tools/test/signature/converter/util/CompilationUnit.java b/tools/signature-tools/test/signature/converter/util/CompilationUnit.java
deleted file mode 100644
index 95960ae..0000000
--- a/tools/signature-tools/test/signature/converter/util/CompilationUnit.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.util;
-
-public class CompilationUnit {
-
- /** a.b.C */
- private String name;
- private String source;
-
- public CompilationUnit(String name, String source) {
- this.name = name;
- this.source = source;
- }
-
- public String getName() {
- return name;
- }
-
- public String getSource() {
- return source;
- }
-}
diff --git a/tools/signature-tools/test/signature/converter/util/ITestSourceConverter.java b/tools/signature-tools/test/signature/converter/util/ITestSourceConverter.java
deleted file mode 100644
index 568a3e9..0000000
--- a/tools/signature-tools/test/signature/converter/util/ITestSourceConverter.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2009 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 signature.converter.util;
-
-import java.io.IOException;
-import java.util.Set;
-
-import signature.converter.Visibility;
-import signature.model.IApi;
-
-public interface ITestSourceConverter {
- IApi convert(Set<CompilationUnit> units) throws IOException;
- IApi convert(CompilationUnit... units) throws IOException;
- IApi convert(Visibility visibility, Set<CompilationUnit> units) throws IOException;
- IApi convert(Visibility visibility, CompilationUnit... units) throws IOException;
-}
diff --git a/tools/tradefed-host/etc/cts-tradefed b/tools/tradefed-host/etc/cts-tradefed
index 5903454..3df2720 100755
--- a/tools/tradefed-host/etc/cts-tradefed
+++ b/tools/tradefed-host/etc/cts-tradefed
@@ -35,9 +35,9 @@
checkPath java
# check java version
-JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '[ "]1\.[67][\. "$$]')
+JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '[ "]1\.[678][\. "$$]')
if [ "${JAVA_VERSION}" == "" ]; then
- echo "Wrong java version. 1.6 or 1.7 is required."
+ echo "Wrong java version. 1.6, 1.7 or 1.8 is required."
exit
fi
diff --git a/tools/utils/CollectAllTests.java b/tools/utils/CollectAllTests.java
index 83c451e..0bce11c 100644
--- a/tools/utils/CollectAllTests.java
+++ b/tools/utils/CollectAllTests.java
@@ -220,6 +220,13 @@
continue;
}
+ // Avoid inner classes: they should not have tests and often they can have dependencies
+ // on test frameworks that need to be resolved and would need to be on the classpath.
+ // e.g. Mockito.
+ if (className.contains("$")) {
+ continue;
+ }
+
try {
Class<?> klass = Class.forName(className,
false,
diff --git a/tools/vm-tests-tf/Android.mk b/tools/vm-tests-tf/Android.mk
index b1cbe37..1e7be8a 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -66,10 +66,8 @@
intermediates := $(call intermediates-dir-for,JAVA_LIBRARIES,vm-tests-tf,HOST)
vmteststf_jar := $(intermediates)/android.core.vm-tests-tf.jar
vmteststf_dep_jars := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/, cts-tf-dalvik-buildutil.jar dasm.jar dx.jar cfassembler.jar junit.jar)
-vmteststf_dep_jars += $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/, jack.jar)
vmteststf_dep_jars += $(private_jill_jarjar_asm)
-$(vmteststf_jar): PRIVATE_JACK_VM_ARGS := $(LOCAL_JACK_VM_ARGS)
$(vmteststf_jar): PRIVATE_JACK_EXTRA_ARGS := $(LOCAL_JACK_EXTRA_ARGS)
ifdef LOCAL_JACK_ENABLED
@@ -84,7 +82,7 @@
$(vmteststf_jar): PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES := $(intermediates)/hostjunit_files
$(vmteststf_jar): PRIVATE_CLASS_PATH := $(subst $(space),:,$(vmteststf_dep_jars)):$(HOST_JDK_TOOLS_JAR)
ifndef LOCAL_JACK_ENABLED
-$(vmteststf_jar) : $(vmteststf_dep_jars) $(JACK_JAR) $(JILL_JAR) $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
+$(vmteststf_jar) : $(vmteststf_dep_jars) $(JILL_JAR) $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
# generated and compile the host side junit tests
@@ -100,24 +98,29 @@
$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../android.core.vm-tests-tf.jar .
$(hide) cd $(dir $@) && zip -q -r android.core.vm-tests-tf.jar tests
else # LOCAL_JACK_ENABLED
-$(vmteststf_jar) : $(vmteststf_dep_jars) $(JACK_JAR) $(JILL_JAR) $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jack $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
+oj_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-oj,,COMMON)/classes.jack
+libart_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jack
+$(vmteststf_jar): PRIVATE_DALVIK_SUITE_CLASSPATH := $(oj_jack):$(libart_jack):$(cts-tf-dalvik-lib.jack):$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
+$(vmteststf_jar) : $(vmteststf_dep_jars) $(JACK) $(JILL_JAR) $(oj_jack) $(libart_jack) $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar | setup-jack-server
$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
# generated and compile the host side junit tests
@echo "Write generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
- $(hide) java -cp $(PRIVATE_CLASS_PATH) util.build.JackBuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
- $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jack:$(cts-tf-dalvik-lib.jack):$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar \
+ $(hide) JACK_VERSION=$(JACK_DEFAULT_VERSION) java -cp $(PRIVATE_CLASS_PATH) util.build.JackBuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
+ $(PRIVATE_DALVIK_SUITE_CLASSPATH) \
$(PRIVATE_INTERMEDIATES_MAIN_FILES) $(PRIVATE_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
@echo "Generate $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)"
$(hide) jar -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar \
$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
$(hide) $(JILL) --output $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar
$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp
- $(hide) $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) --output-dex $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp \
+ $(hide) $(call call-jack,$(PRIVATE_JACK_EXTRA_ARGS)) --output-dex $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp \
$(if $(NO_OPTIMIZE_DX), -D jack.dex.optimize "false") --import $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack
$(hide) cd $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp && zip -q -r $(abspath $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)) .
$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../android.core.vm-tests-tf.jar .
$(hide) cd $(dir $@) && zip -q -r android.core.vm-tests-tf.jar tests
+oj_jack :=
+libart_jack :=
endif # LOCAL_JACK_ENABLED
# Clean up temp vars
diff --git a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
index 0e31884..a25fce2 100644
--- a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
+++ b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
@@ -19,6 +19,7 @@
import com.android.dex.util.FileUtils;
import dot.junit.AllTests;
+import util.build.BuildStep.BuildFile;
import junit.framework.TestCase;
import junit.framework.TestResult;
@@ -56,6 +57,8 @@
*/
public class BuildDalvikSuite {
+ public static final String TARGET_MAIN_FILE = "mains.jar";
+
public static boolean DEBUG = true;
private static String JAVASRC_FOLDER = "";
@@ -257,14 +260,10 @@
final String targetCoreJarPath = String.format("%s/dot/junit/dexcore.jar",
TARGET_JAR_ROOT_PATH);
- // push class with Main jar.
- String mjar = "Main_" + method + ".jar";
- String pPath = pName.replaceAll("\\.","/");
- String mainJar = String.format("%s/%s/%s", TARGET_JAR_ROOT_PATH, pPath, mjar);
+ String mainsJar = String.format("%s/%s", TARGET_JAR_ROOT_PATH, TARGET_MAIN_FILE);
- String cp = String.format("%s:%s", targetCoreJarPath, mainJar);
+ String cp = String.format("%s:%s", targetCoreJarPath, mainsJar);
for (String depFqcn : dependentTestClassNames) {
- int lastDotPos = depFqcn.lastIndexOf('.');
String sourceName = depFqcn.replaceAll("\\.", "/") + ".jar";
String targetName= String.format("%s/%s", TARGET_JAR_ROOT_PATH,
sourceName);
@@ -289,7 +288,13 @@
hostJunitBuildStep = new JavacBuildStep(
HOSTJUNIT_CLASSES_OUTPUT_FOLDER, CLASS_PATH);
- srcBuildStep = new JavacBuildStep(CLASSES_OUTPUT_FOLDER, CLASS_PATH);
+ String mainsJar = OUTPUT_FOLDER + File.separator + TARGET_MAIN_FILE;
+ if (useJack) {
+ srcBuildStep = new JackBuildStep(mainsJar,
+ CLASS_PATH);
+ } else {
+ srcBuildStep = new JavacBuildStep(CLASSES_OUTPUT_FOLDER, CLASS_PATH);
+ }
for (Entry<String, List<String>> entry : map.entrySet()) {
@@ -355,23 +360,7 @@
File sourceFile = getFileFromPackage(pName, method);
writeToFile(sourceFile, content);
- if (useJack) {
- File jackFile = new File(CLASSES_OUTPUT_FOLDER + "/" +
- getFileName(pName, method, ".jack"));
- JackBuildStep step = new JackBuildStep(jackFile.getAbsolutePath(), CLASS_PATH);
- step.addSourceFile(sourceFile.getAbsolutePath());
- if (!step.build()) {
- System.out.println("main src dalvik-cts-buildutil build step failed");
- System.exit(1);
- }
- } else {
- srcBuildStep.addSourceFile(sourceFile.getAbsolutePath());
- }
-
- BuildStep dexBuildStep = generateDexBuildStep(
- CLASSES_OUTPUT_FOLDER, getFileName(pName, method, ""), null);
- targets.add(dexBuildStep);
-
+ srcBuildStep.addSourceFile(sourceFile.getAbsolutePath());
// prepare the entry in the data file for the bash script.
// e.g.
@@ -459,6 +448,15 @@
}
+ if (!useJack) {
+ DxBuildStep dexBuildStep = new DxBuildStep(
+ new BuildStep.BuildFile(new File(CLASSES_OUTPUT_FOLDER)),
+ new BuildStep.BuildFile(new File(mainsJar)),
+ false);
+
+ targets.add(dexBuildStep);
+ }
+
// write latest HOSTJUNIT generated file.
flushHostJunitFile();
@@ -471,12 +469,11 @@
System.exit(1);
}
- if (!useJack) {
- if (!srcBuildStep.build()) {
- System.out.println("main src dalvik-cts-buildutil build step failed");
- System.exit(1);
- }
+ if (!srcBuildStep.build()) {
+ System.out.println("main src dalvik-cts-buildutil build step failed");
+ System.exit(1);
}
+
for (BuildStep buildStep : targets) {
if (!buildStep.build()) {
System.out.println("building failed. buildStep: " +
@@ -541,15 +538,17 @@
File srcFile = new File(sourceFolder, fileName + ".java");
if (srcFile.exists()) {
- JackBuildStep jackBuildStep = null;
+ BuildStep dexBuildStep;
if (useJack) {
- jackBuildStep = new JackBuildStep(
- COMPILED_CLASSES_FOLDER + File.separator + fileName + ".jack",
+ JackBuildStep jackBuildStep = new JackBuildStep(
+ OUTPUT_FOLDER + File.separator + fileName + ".jar",
CLASS_PATH);
jackBuildStep.addSourceFile(srcFile.getAbsolutePath());
+ dexBuildStep = jackBuildStep;
+ } else {
+ dexBuildStep = generateDexBuildStep(
+ COMPILED_CLASSES_FOLDER, fileName, null);
}
- BuildStep dexBuildStep = generateDexBuildStep(
- COMPILED_CLASSES_FOLDER, fileName, jackBuildStep);
targets.add(dexBuildStep);
return;
}
diff --git a/tools/vm-tests-tf/src/util/build/BuildStep.java b/tools/vm-tests-tf/src/util/build/BuildStep.java
index dbc6bca..e3349bd 100644
--- a/tools/vm-tests-tf/src/util/build/BuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/BuildStep.java
@@ -37,6 +37,10 @@
this.folder = new File(folder);
this.fileName = new File(this.folder, fileName);
}
+ BuildFile(File file) {
+ this.folder = file.getParentFile();
+ this.fileName = file;
+ }
String getPath() {
return fileName.getAbsolutePath();
@@ -70,7 +74,8 @@
this.outputFile = outputFile;
}
- BuildStep() {
+ BuildStep(File output) {
+ this.outputFile = new BuildFile(output);
}
private Set<BuildStep> children;
@@ -117,8 +122,7 @@
}
public int compareTo(BuildStep o) {
- return (inputFile == o.inputFile ? 0 : (inputFile != null
- ? (o.inputFile != null ? inputFile.getPath().compareTo(
- o.inputFile.getPath()) : 1) : -1));
+ return (outputFile == o.outputFile ? 0 : outputFile.getPath().compareTo(
+ o.outputFile.getPath()));
}
}
diff --git a/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java b/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java
new file mode 100644
index 0000000..f243c17
--- /dev/null
+++ b/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 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 util.build;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Class that continuously read an {@link InputStream} and optionally could write the input in a
+ * {@link OutputStream}.
+ */
+public class BytesStreamSucker {
+
+ private static final int BUFFER_SIZE = 4096;
+
+ @Nonnull
+ private final byte[] buffer = new byte[BUFFER_SIZE];
+
+ @Nonnull
+ private final InputStream is;
+
+ @Nonnull
+ private final OutputStream os;
+
+ private final boolean toBeClose;
+
+ public BytesStreamSucker(
+ @Nonnull InputStream is, @Nonnull OutputStream os, boolean toBeClose) {
+ this.is = is;
+ this.os = os;
+ this.toBeClose = toBeClose;
+ }
+
+ public BytesStreamSucker(@Nonnull InputStream is, @Nonnull OutputStream os) {
+ this(is, os, false);
+ }
+
+ public void suck() throws IOException {
+ try {
+ int bytesRead;
+ while ((bytesRead = is.read(buffer)) >= 0) {
+ os.write(buffer, 0, bytesRead);
+ os.flush();
+ }
+ } finally {
+ if (toBeClose) {
+ os.close();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java b/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java
new file mode 100644
index 0000000..ce4dfb1
--- /dev/null
+++ b/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 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 util.build;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Class that continuously read an {@link InputStream} and optionally could print the input in a
+ * {@link PrintStream}.
+ */
+public class CharactersStreamSucker {
+
+ @Nonnull
+ private final BufferedReader ir;
+
+ @Nonnull
+ private final PrintStream os;
+
+ private final boolean toBeClose;
+
+ public CharactersStreamSucker(
+ @Nonnull InputStream is, @Nonnull PrintStream os, boolean toBeClose) {
+ this.ir = new BufferedReader(new InputStreamReader(is));
+ this.os = os;
+ this.toBeClose = toBeClose;
+ }
+
+ public CharactersStreamSucker(@Nonnull InputStream is, @Nonnull PrintStream os) {
+ this(is, os, false);
+ }
+
+ public void suck() throws IOException {
+ String line;
+
+ try {
+ while ((line = ir.readLine()) != null) {
+ os.println(line);
+ }
+ } finally {
+ if (toBeClose) {
+ os.close();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/ExecuteFile.java b/tools/vm-tests-tf/src/util/build/ExecuteFile.java
new file mode 100644
index 0000000..a0e5ce5
--- /dev/null
+++ b/tools/vm-tests-tf/src/util/build/ExecuteFile.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright (C) 2012 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 util.build;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * Class to handle the execution of an external process
+ */
+public class ExecuteFile {
+ @Nonnull
+ private final String[] cmdLine;
+
+ @CheckForNull
+ private File workDir;
+
+ @CheckForNull
+ private InputStream inStream;
+ private boolean inToBeClose;
+
+ @CheckForNull
+ private OutputStream outStream;
+ private boolean outToBeClose;
+
+ @CheckForNull
+ private OutputStream errStream;
+ private boolean errToBeClose;
+ private boolean verbose;
+
+ @Nonnull
+ private final Logger logger = Logger.getLogger(this.getClass().getName());
+
+ public void setErr(@Nonnull File file) throws FileNotFoundException {
+ errStream = new FileOutputStream(file);
+ errToBeClose = true;
+ }
+
+ public void setOut(@Nonnull File file) throws FileNotFoundException {
+ outStream = new FileOutputStream(file);
+ outToBeClose = true;
+ }
+
+ public void setIn(@Nonnull File file) throws FileNotFoundException {
+ inStream = new FileInputStream(file);
+ inToBeClose = true;
+ }
+
+ public void setErr(@Nonnull OutputStream stream) {
+ errStream = stream;
+ }
+
+ public void setOut(@Nonnull OutputStream stream) {
+ outStream = stream;
+ }
+
+ public void setIn(@Nonnull InputStream stream) {
+ inStream = stream;
+ }
+
+ public void setWorkingDir(@Nonnull File dir, boolean create) throws IOException {
+ if (!dir.isDirectory()) {
+ if (create && !dir.exists()) {
+ if (!dir.mkdirs()) {
+ throw new IOException("Directory creation failed");
+ }
+ } else {
+ throw new FileNotFoundException(dir.getPath() + " is not a directory");
+ }
+ }
+
+ workDir = dir;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public ExecuteFile(@Nonnull File exec, @Nonnull String[] args) {
+ cmdLine = new String[args.length + 1];
+ System.arraycopy(args, 0, cmdLine, 1, args.length);
+
+ cmdLine[0] = exec.getAbsolutePath();
+ }
+
+ public ExecuteFile(@Nonnull String exec, @Nonnull String[] args) {
+ cmdLine = new String[args.length + 1];
+ System.arraycopy(args, 0, cmdLine, 1, args.length);
+
+ cmdLine[0] = exec;
+ }
+
+ public ExecuteFile(@Nonnull File exec) {
+ cmdLine = new String[1];
+ cmdLine[0] = exec.getAbsolutePath();
+ }
+
+ public ExecuteFile(@Nonnull String[] cmdLine) {
+ this.cmdLine = cmdLine.clone();
+ }
+
+ public ExecuteFile(@Nonnull String cmdLine) throws IOException {
+ StringReader reader = new StringReader(cmdLine);
+ StreamTokenizer tokenizer = new StreamTokenizer(reader);
+ tokenizer.resetSyntax();
+ // Only standard spaces are recognized as whitespace chars
+ tokenizer.whitespaceChars(' ', ' ');
+ // Matches alphanumerical and common special symbols like '(' and ')'
+ tokenizer.wordChars('!', 'z');
+ // Quote chars will be ignored when parsing strings
+ tokenizer.quoteChar('\'');
+ tokenizer.quoteChar('\"');
+ ArrayList<String> tokens = new ArrayList<String>();
+ while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
+ String token = tokenizer.sval;
+ if (token != null) {
+ tokens.add(token);
+ }
+ }
+ this.cmdLine = tokens.toArray(new String[0]);
+ }
+
+ public boolean run() {
+ int ret;
+ Process proc = null;
+ Thread suckOut = null;
+ Thread suckErr = null;
+ Thread suckIn = null;
+
+ try {
+ StringBuilder cmdLineBuilder = new StringBuilder();
+ for (String arg : cmdLine) {
+ cmdLineBuilder.append(arg).append(' ');
+ }
+ if (verbose) {
+ PrintStream printStream;
+ if (outStream instanceof PrintStream) {
+ printStream = (PrintStream) outStream;
+ } else {
+ printStream = System.out;
+ }
+
+ if (printStream != null) {
+ printStream.println(cmdLineBuilder);
+ }
+ } else {
+ logger.log(Level.FINE, "Execute: {0}", cmdLineBuilder);
+ }
+
+ proc = Runtime.getRuntime().exec(cmdLine, null, workDir);
+
+ InputStream localInStream = inStream;
+ if (localInStream != null) {
+ suckIn = new Thread(
+ new ThreadBytesStreamSucker(localInStream, proc.getOutputStream(), inToBeClose));
+ } else {
+ proc.getOutputStream().close();
+ }
+
+ OutputStream localOutStream = outStream;
+ if (localOutStream != null) {
+ if (localOutStream instanceof PrintStream) {
+ suckOut = new Thread(new ThreadCharactersStreamSucker(proc.getInputStream(),
+ (PrintStream) localOutStream, outToBeClose));
+ } else {
+ suckOut = new Thread(
+ new ThreadBytesStreamSucker(proc.getInputStream(), localOutStream, outToBeClose));
+ }
+ }
+
+ OutputStream localErrStream = errStream;
+ if (localErrStream != null) {
+ if (localErrStream instanceof PrintStream) {
+ suckErr = new Thread(new ThreadCharactersStreamSucker(proc.getErrorStream(),
+ (PrintStream) localErrStream, errToBeClose));
+ } else {
+ suckErr = new Thread(
+ new ThreadBytesStreamSucker(proc.getErrorStream(), localErrStream, errToBeClose));
+ }
+ }
+
+ if (suckIn != null) {
+ suckIn.start();
+ }
+ if (suckOut != null) {
+ suckOut.start();
+ }
+ if (suckErr != null) {
+ suckErr.start();
+ }
+
+ proc.waitFor();
+ if (suckIn != null) {
+ suckIn.join();
+ }
+ if (suckOut != null) {
+ suckOut.join();
+ }
+ if (suckErr != null) {
+ suckErr.join();
+ }
+
+ ret = proc.exitValue();
+ proc.destroy();
+
+ return ret == 0;
+ } catch (Throwable e) {
+ return false;
+ }
+ }
+
+ private static class ThreadBytesStreamSucker extends BytesStreamSucker implements Runnable {
+
+ public ThreadBytesStreamSucker(@Nonnull InputStream is, @Nonnull OutputStream os,
+ boolean toBeClose) {
+ super(is, os, toBeClose);
+ }
+
+ @Override
+ public void run() {
+ try {
+ suck();
+ } catch (IOException e) {
+ // Best effort
+ }
+ }
+ }
+
+ private static class ThreadCharactersStreamSucker extends CharactersStreamSucker implements
+ Runnable {
+
+ public ThreadCharactersStreamSucker(@Nonnull InputStream is, @Nonnull PrintStream ps,
+ boolean toBeClose) {
+ super(is, ps, toBeClose);
+ }
+
+ @Override
+ public void run() {
+ try {
+ suck();
+ } catch (IOException e) {
+ // Best effort
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/JackBuildStep.java b/tools/vm-tests-tf/src/util/build/JackBuildStep.java
index 1e1ede6..29df8260 100644
--- a/tools/vm-tests-tf/src/util/build/JackBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/JackBuildStep.java
@@ -16,11 +16,10 @@
package util.build;
-import com.android.jack.Jack;
-import com.android.jack.Main;
-import com.android.jack.Options;
-
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -33,6 +32,7 @@
private final Set<String> sourceFiles = new HashSet<String>();
public JackBuildStep(String destPath, String classPath) {
+ super(new File(destPath));
this.destPath = destPath;
this.classPath = classPath;
}
@@ -55,23 +55,67 @@
+ outDir.getAbsolutePath());
return false;
}
- List<String> commandLine = new ArrayList(4 + sourceFiles.size());
- commandLine.add("--verbose");
- commandLine.add("error");
- commandLine.add("--classpath");
- commandLine.add(classPath);
- commandLine.add("--output-jack");
- commandLine.add(destPath);
- commandLine.addAll(sourceFiles);
+ File tmpOutDir = new File(outDir, outputFile.fileName.getName() + ".dexTmp");
+ if (!tmpOutDir.exists() && !tmpOutDir.mkdirs()) {
+ System.err.println("failed to create temp dir: "
+ + tmpOutDir.getAbsolutePath());
+ return false;
+ }
+ File tmpDex = new File(tmpOutDir, "classes.dex");
+
+ File tmpArgs = new File(outDir, outputFile.fileName.getName() + ".args");
+
+ Writer argsOut = null;
try {
- Options options = Main.parseCommandLine(commandLine);
- Jack.checkAndRun(options);
+ argsOut = new FileWriter(tmpArgs);
+ for (String source : sourceFiles) {
+ argsOut.append(source);
+ argsOut.append('\n');
+ }
+ argsOut.close();
+ argsOut = null;
+
+ List<String> commandLine = new ArrayList<String>(6 + sourceFiles.size());
+ commandLine.add("--verbose");
+ commandLine.add("error");
+ commandLine.add("--classpath");
+ commandLine.add(classPath);
+ commandLine.add("--output-dex");
+ commandLine.add(tmpOutDir.getAbsolutePath());
+ commandLine.add("@" + tmpArgs.getPath());
+
+ ExecuteFile exec = new ExecuteFile("jack", commandLine.toArray(new String[commandLine.size()]));
+ exec.setErr(System.err);
+ exec.setOut(System.out);
+ if (!exec.run()) {
+ return false;
+ }
+
+ JarBuildStep jarStep = new JarBuildStep(
+ new BuildFile(tmpDex),
+ "classes.dex",
+ outputFile,
+ /* deleteInputFileAfterBuild = */ true);
+ if (!jarStep.build()) {
+ throw new IOException("Failed to make jar: " + outputFile.getPath());
+ }
+ return true;
} catch (Throwable ex) {
ex.printStackTrace();
return false;
+ } finally {
+ tmpDex.delete();
+ tmpArgs.delete();
+ tmpOutDir.delete();
+ if (argsOut != null) {
+ try {
+ argsOut.close();
+ } catch (IOException io) {
+ // Ignore, don't override already thrown exception
+ }
+ }
}
- return true;
}
return false;
}
diff --git a/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java b/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java
index 304eaa0..3702973 100644
--- a/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java
@@ -16,11 +16,8 @@
package util.build;
-import com.android.jack.Jack;
-import com.android.jack.Main;
-import com.android.jack.Options;
-
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +38,7 @@
String outputFilePath = outputFile.fileName.getAbsolutePath();
if (outputFilePath.endsWith(".dex")) {
throw new AssertionError(
- "DexBuildStep does not support dex output outside of an archive");
+ "JackDexBuildStep does not support dex output outside of an archive");
}
File outDir = outputFile.fileName.getParentFile();
@@ -51,17 +48,38 @@
return false;
}
- List<String> commandLine = new ArrayList<String>(4);
- commandLine.add("--verbose");
- commandLine.add("error");
- commandLine.add("--output-dex-zip");
- commandLine.add(outputFilePath);
- commandLine.add("--import");
- commandLine.add(inputFile.fileName.getAbsolutePath());
+ File tmpOutDir = new File(outDir, outputFile.fileName.getName() + ".dexTmp");
+ if (!tmpOutDir.exists() && !tmpOutDir.mkdirs()) {
+ System.err.println("failed to create temp dir: "
+ + tmpOutDir.getAbsolutePath());
+ return false;
+ }
+ File tmpDex = new File(tmpOutDir, "classes.dex");
try {
- Options options = Main.parseCommandLine(commandLine);
- Jack.checkAndRun(options);
+ List<String> commandLine = new ArrayList<String>(4);
+ commandLine.add("--verbose");
+ commandLine.add("error");
+ commandLine.add("--output-dex");
+ commandLine.add(tmpOutDir.getAbsolutePath());
+ commandLine.add("--import");
+ commandLine.add(inputFile.fileName.getAbsolutePath());
+
+ ExecuteFile exec = new ExecuteFile("jack", commandLine.toArray(new String[commandLine.size()]));
+ exec.setErr(System.err);
+ exec.setOut(System.out);
+ if (!exec.run()) {
+ return false;
+ }
+
+ JarBuildStep jarStep = new JarBuildStep(
+ new BuildFile(tmpDex),
+ "classes.dex",
+ outputFile,
+ /* deleteInputFileAfterBuild = */ true);
+ if (!jarStep.build()) {
+ throw new IOException("Failed to make jar: " + outputFile.getPath());
+ }
if (deleteInputFileAfterBuild) {
inputFile.fileName.delete();
}
@@ -71,6 +89,9 @@
+ inputFile.fileName.getAbsolutePath() + " to "
+ outputFile.fileName.getAbsolutePath());
ex.printStackTrace();
+ } finally {
+ tmpDex.delete();
+ tmpOutDir.delete();
}
}
return false;
diff --git a/tools/vm-tests-tf/src/util/build/JavacBuildStep.java b/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
index d08a2c6..a1cde1f 100644
--- a/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
@@ -29,6 +29,7 @@
private final String classPath;
private final Set<String> sourceFiles = new HashSet<String>();
public JavacBuildStep(String destPath, String classPath) {
+ super(new File(destPath));
this.destPath = destPath;
this.classPath = classPath;
}
@@ -54,12 +55,16 @@
System.err.println("failed to create destination dir");
return false;
}
- int args = 4;
+ int args = 8;
String[] commandLine = new String[sourceFiles.size()+args];
commandLine[0] = "-classpath";
commandLine[1] = classPath;
commandLine[2] = "-d";
commandLine[3] = destPath;
+ commandLine[4] = "-source";
+ commandLine[5] = "1.7";
+ commandLine[6] = "-target";
+ commandLine[7] = "1.7";
String[] files = new String[sourceFiles.size()];
sourceFiles.toArray(files);
diff --git a/tools/vm-tests-tf/src/util/build/SourceBuildStep.java b/tools/vm-tests-tf/src/util/build/SourceBuildStep.java
index 4a68a05..9f9142d 100644
--- a/tools/vm-tests-tf/src/util/build/SourceBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/SourceBuildStep.java
@@ -16,8 +16,14 @@
package util.build;
+import java.io.File;
+
public abstract class SourceBuildStep extends BuildStep {
+ SourceBuildStep(File destFile) {
+ super(destFile);
+ }
+
public abstract void addSourceFile(String sourceFile);
}