";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/shaking/ProguardKeepRuleType.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.shaking;
5 |
6 | import com.android.tools.r8.errors.Unreachable;
7 |
8 | public enum ProguardKeepRuleType {
9 | KEEP,
10 | KEEP_CLASS_MEMBERS,
11 | KEEP_CLASSES_WITH_MEMBERS;
12 |
13 | @Override
14 | public String toString() {
15 | switch (this) {
16 | case KEEP:
17 | return "keep";
18 | case KEEP_CLASS_MEMBERS:
19 | return "keepclassmembers";
20 | case KEEP_CLASSES_WITH_MEMBERS:
21 | return "keepclasseswithmembers";
22 | default:
23 | throw new Unreachable("Unknown ProguardKeepRuleType.");
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/shaking/ProguardMemberType.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.shaking;
5 |
6 | public enum ProguardMemberType {
7 | // Please keep the order so fields are before methods
8 | FIELD,
9 | ALL_FIELDS,
10 | ALL,
11 | ALL_METHODS,
12 | INIT,
13 | CONSTRUCTOR,
14 | METHOD;
15 |
16 | public boolean includesFields() {
17 | return ordinal() <= ALL.ordinal();
18 | }
19 |
20 | public boolean includesMethods() {
21 | return ordinal() >= ALL.ordinal();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/shaking/ProguardRuleParserException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.shaking;
5 |
6 | public class ProguardRuleParserException extends Exception {
7 | public ProguardRuleParserException(String message, String snippet) {
8 | this(message, snippet, null);
9 | }
10 |
11 | public ProguardRuleParserException(String message, String snippet, Throwable cause) {
12 | super(message + " at " + snippet, cause);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/utils/FieldSignatureEquivalence.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.utils;
5 |
6 | import com.android.tools.r8.graph.DexField;
7 | import com.google.common.base.Equivalence;
8 |
9 | /**
10 | * Implements an equivalence on {@link DexField} that does not take the holder into account.
11 | *
12 | * Useful when comparing method implementations by their signature only.
13 | */
14 | public class FieldSignatureEquivalence extends Equivalence {
15 |
16 | private static final FieldSignatureEquivalence THEINSTANCE = new FieldSignatureEquivalence();
17 |
18 | private FieldSignatureEquivalence() {
19 | }
20 |
21 | public static FieldSignatureEquivalence get() {
22 | return THEINSTANCE;
23 | }
24 |
25 | @Override
26 | protected boolean doEquivalent(DexField a, DexField b) {
27 | return a.name.equals(b.name) && a.type.equals(b.type);
28 | }
29 |
30 | @Override
31 | protected int doHash(DexField field) {
32 | return field.name.hashCode() * 31 + field.type.hashCode();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/utils/ListUtils.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | package com.android.tools.r8.utils;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 | import java.util.function.Function;
11 |
12 | public class ListUtils {
13 |
14 | public static List map(Collection list, Function fn) {
15 | List result = new ArrayList<>(list.size());
16 | for (S element : list) {
17 | result.add(fn.apply(element));
18 | }
19 | return result;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/utils/OffOrAuto.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | package com.android.tools.r8.utils;
6 |
7 | import joptsimple.ValueConversionException;
8 | import joptsimple.ValueConverter;
9 |
10 | public enum OffOrAuto {
11 | Off, Auto;
12 |
13 | static final ValueConverter CONVERTER = new ValueConverter() {
14 | @Override
15 | public OffOrAuto convert(String input) {
16 | try {
17 | input = Character.toUpperCase(input.charAt(0)) + input.substring(1).toLowerCase();
18 | return Enum.valueOf(OffOrAuto.class, input);
19 | } catch (Exception e) {
20 | throw new ValueConversionException("Value must be one of: " + valuePattern());
21 | }
22 | }
23 |
24 | @Override
25 | public Class valueType() {
26 | return OffOrAuto.class;
27 | }
28 |
29 | @Override
30 | public String valuePattern() {
31 | return "off|auto";
32 | }
33 | };
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/utils/OneShotByteResource.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.utils;
5 |
6 | import com.android.tools.r8.Resource;
7 | import java.io.ByteArrayInputStream;
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.util.Set;
11 |
12 | class OneShotByteResource extends Resource {
13 |
14 | private byte[] bytes;
15 | private final Set classDescriptors;
16 |
17 | OneShotByteResource(Kind kind, byte[] bytes, Set classDescriptors) {
18 | super(kind);
19 | assert bytes != null;
20 | this.bytes = bytes;
21 | this.classDescriptors = classDescriptors;
22 | }
23 |
24 | @Override
25 | public Set getClassDescriptors() {
26 | return classDescriptors;
27 | }
28 |
29 | @Override
30 | public InputStream getStream() throws IOException {
31 | assert bytes != null;
32 | InputStream result = new ByteArrayInputStream(bytes);
33 | bytes = null;
34 | return result;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/android/tools/r8/utils/OutputMode.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 | package com.android.tools.r8.utils;
5 |
6 | import com.android.tools.r8.Resource;
7 | import java.util.Set;
8 |
9 | /** Defines way the output is formed. */
10 | public enum OutputMode {
11 | Indexed {
12 | @Override
13 | String getOutputPath(Resource resource, int index) {
14 | return index == 0 ? "classes.dex" : ("classes" + (index + 1) + ".dex");
15 | }
16 | },
17 | FilePerClass {
18 | @Override
19 | String getOutputPath(Resource resource, int index) {
20 | Set classDescriptors = resource.getClassDescriptors();
21 | assert classDescriptors != null;
22 | assert classDescriptors.size() == 1;
23 | String classDescriptor = classDescriptors.iterator().next();
24 | assert DescriptorUtils.isClassDescriptor(classDescriptor);
25 | return classDescriptor.substring(1, classDescriptor.length() - 1) + ".dex";
26 | }
27 | };
28 |
29 | abstract String getOutputPath(Resource resource, int index);
30 | }
31 |
--------------------------------------------------------------------------------