summaryrefslogtreecommitdiff
path: root/test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-12-06 15:47:08 -0800
committerColin Cross <ccross@android.com>2017-12-06 15:47:08 -0800
commit00ed747d46416ee1f4dcda253722d57ef48acea7 (patch)
tree357d9e70cc17ca529f75ca1f92a1f70f71884583 /test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java
parent96f19e7df85b15fbfc0d6705fa969f216b7346a6 (diff)
parent399ca0fdaa1cbd7120b07df54b207aad2d6fe77c (diff)
downloaddesugar-00ed747d46416ee1f4dcda253722d57ef48acea7.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into desugar
* aosp/upstream-master: Improve exception message to output more information. RELNOTES:None. Remove static import of inner class InferredType's fields Automatic code cleanup. Let to push lambda arguments not only with *LOAD instructions but with SIPUSH and *CONST_*. Fix canonical option list for options that implicitly require options with allowMultiple=true Change config expansion application order, gated by startup flag --expand_configs_in_place. Specialize $closeResource(Throwable, AutoCloseable) so that desugared code does not depend on AutoCloseable, as it is not available before API 19. Fix EnclosingMethod attribute when moving interface methods to companion class RELNOTES: None. Cleanup stream use in canonical list of options. Remove unused LegacyParamsFilePreProcessor. Removed test cases from OptionsParserTest are implemented in ParamsFilePreProcessorTest, ShellQuotedParamsFilePreProcessorTest and UnquotedParamsFilePreProcessorTest. Switch on tracking of specific option priorities. Compute canonical list of options using OptionValueDescription's tracking of instances. Test: m checkbuild Change-Id: Idb762b0dabc9660d9116d1b976fb2f74aa7f5e09
Diffstat (limited to 'test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java')
-rw-r--r--test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java196
1 files changed, 196 insertions, 0 deletions
diff --git a/test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java b/test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java
new file mode 100644
index 0000000..b5463a7
--- /dev/null
+++ b/test/java/com/google/devtools/build/android/desugar/classes_for_testing_type_inference/testsubjects/TestSubject.java
@@ -0,0 +1,196 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// 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 testsubjects;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.function.BinaryOperator;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Test subject for testing bytecode type inference {@link
+ * com.google.devtools.build.android.desugar.BytecodeTypeInference}
+ */
+public class TestSubject {
+
+ private static int VALUE_ONE = 1;
+ private static int VALUE_TWO = 2;
+
+ static int catchTest(Object key, Object value) {
+ if (!(key instanceof String)) {
+ return VALUE_ONE;
+ }
+ try {
+ Pattern.compile((String) key);
+ } catch (PatternSyntaxException e) {
+ return VALUE_TWO;
+ }
+ return VALUE_ONE;
+ }
+
+ public static void assertEquals(String message, double expected, double actual, double delta) {
+ if (Double.compare(expected, actual) == 0) {
+ return;
+ }
+ if (!(Math.abs(expected - actual) <= delta)) {
+ throw new RuntimeException(message + new Double(expected) + new Double(actual));
+ }
+ }
+
+ /**
+ * A simple resource implementation which implements Closeable.
+ */
+ public static class SimpleResource implements Closeable {
+
+ public void call(boolean throwException) {
+ if (throwException) {
+ throw new RuntimeException("exception in call()");
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ throw new IOException("exception in close().");
+ }
+ }
+
+ public static void simpleTryWithResources() throws Exception {
+ // Throwable.addSuppressed(Throwable) should be called in the following block.
+ try (SimpleResource resource = new SimpleResource()) {
+ resource.call(true);
+ }
+ }
+
+ private static long internalCompare(long a, long b, BinaryOperator<Long> func) {
+ return func.apply(a, b);
+ }
+
+ public void closeResourceArray(Statement[] resources) throws Exception {
+ for (Statement stmt : resources) {
+ closeResource(stmt, null);
+ }
+ }
+
+ public void closeResourceMultiArray(Statement[][] resources) throws Exception {
+ for (Statement[] stmts : resources) {
+ for (Statement stmt : stmts) {
+ closeResource(stmt, null);
+ }
+ }
+ }
+
+ public void closeResourceArrayList(List<Statement> resources) throws Exception {
+ for (Statement stmt : resources) {
+ closeResource(stmt, null);
+ }
+ }
+
+ public void closeSqlStmt(Connection connection) throws Exception {
+ Statement stmt = null;
+
+ try {
+ stmt = connection.createStatement();
+ } catch (SQLException e) {
+ closeResource(stmt, e);
+ }
+ closeResource(stmt, null);
+ }
+
+ public void closeResource(AutoCloseable resource, Throwable suppressor) throws Exception {
+ if (resource == null) {
+ return;
+ }
+ try {
+ resource.close();
+ } catch (Exception e) {
+ if (suppressor != null) {
+ suppressor.addSuppressed(e);
+ }
+ throw e;
+ }
+ }
+
+ public static int intAdd(int i, int j) {
+ int tmp = i;
+ tmp++;
+ ++tmp;
+ tmp += j;
+ tmp--;
+ --tmp;
+ tmp -= j;
+ tmp *= j;
+ tmp /= j;
+ tmp = tmp % j;
+ tmp = tmp << 2;
+ tmp = tmp >> j;
+ tmp = tmp >>> 3;
+ long longTemp = tmp;
+ longTemp = longTemp << j;
+ return (int) longTemp;
+ }
+
+ public static Number createNumberWithDiamond(boolean flag) {
+ Number n = null;
+ if (flag) {
+ n = new Integer(1);
+ } else {
+ n = new Double(1);
+ }
+ return n;
+ }
+
+ public static Object[][] createMultiObjectArray() {
+ return new Object[0][0];
+ }
+
+ public static Object[] createObjectArray() {
+ return new Object[0];
+ }
+
+ public static int[] createIntArray() {
+ return new int[0];
+ }
+
+ public static void staticEmpty1() {}
+
+ public void instanceEmpty1() {}
+
+ public static boolean identity(boolean result) {
+ return result;
+ }
+
+ public static boolean identity2(boolean result) {
+ boolean temp = result;
+ return temp;
+ }
+
+ public void readFile(File file) throws Exception {
+ try (AutoCloseable reader = new BufferedReader(new FileReader(file));
+ AutoCloseable reader2 = new BufferedReader(new FileReader(file));
+ AutoCloseable reader3 = new BufferedReader(new FileReader(file));
+ AutoCloseable reader4 = new BufferedReader(new FileReader(file))) {
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}