[KeepAnno] Remove deprecated properties
These properties are not used in aosp and can now be removed.
Bug: b/248408342
Change-Id: I4cd9b4ffb7c587382df416c48690a55972d71748
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepBinding.java b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepBinding.java
index 2f8ff1c..364f3a1 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepBinding.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepBinding.java
@@ -79,8 +79,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classAnnotatedByClassName
* <li>classAnnotatedByClassConstant
* <li>classAnnotatedByClassNamePattern
@@ -152,8 +150,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -175,8 +171,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -195,8 +189,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -218,8 +210,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -230,56 +220,6 @@
Class<?> instanceOfClassConstantExclusive() default Object.class;
/**
- * Define the instance-of pattern as classes extending the fully qualified class name.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassConstant
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class name that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassName} instead.
- */
- @Deprecated
- String extendsClassName() default "";
-
- /**
- * Define the instance-of pattern as classes extending the referenced Class constant.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class constant that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassConstant} instead.
- */
- @Deprecated
- Class<?> extendsClassConstant() default Object.class;
-
- /**
* Define the class-annotated-by pattern by fully qualified class name.
*
* <p>Mutually exclusive with the following other properties defining class-annotated-by:
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepCondition.java b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepCondition.java
index 4a39ca8..3a96660 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepCondition.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepCondition.java
@@ -41,8 +41,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classAnnotatedByClassName
* <li>classAnnotatedByClassConstant
* <li>classAnnotatedByClassNamePattern
@@ -114,8 +112,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -137,8 +133,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -157,8 +151,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -180,8 +172,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -192,56 +182,6 @@
Class<?> instanceOfClassConstantExclusive() default Object.class;
/**
- * Define the instance-of pattern as classes extending the fully qualified class name.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassConstant
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class name that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassName} instead.
- */
- @Deprecated
- String extendsClassName() default "";
-
- /**
- * Define the instance-of pattern as classes extending the referenced Class constant.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class constant that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassConstant} instead.
- */
- @Deprecated
- Class<?> extendsClassConstant() default Object.class;
-
- /**
* Define the class-annotated-by pattern by fully qualified class name.
*
* <p>Mutually exclusive with the following other properties defining class-annotated-by:
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepTarget.java b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepTarget.java
index 3d055d0..bf9251b 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepTarget.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/KeepTarget.java
@@ -61,26 +61,35 @@
*
* <p>The specified constraints must remain valid for the target.
*
- * <p>The default constraints depend on the type of the target.
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
*
* <ul>
- * <li>For classes, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#CLASS_INSTANTIATE}}
- * <li>For methods, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#METHOD_INVOKE}}
- * <li>For fields, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#FIELD_GET}, {@link KeepConstraint#FIELD_SET}}
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
* </ul>
*
- * <p>Mutually exclusive with the following other properties defining constraints:
+ * <p>For classes the default constraints also include:
*
* <ul>
- * <li>constraintAdditions
- * <li>allow
- * <li>disallow
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
* </ul>
*
- * <p>If nothing is specified for constraints the default is the default for {@link #constraints}.
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
+ * </ul>
+ *
+ * <p>Mutually exclusive with the property `constraintAdditions` also defining constraints.
*
* @return Usage constraints for the target.
*/
@@ -94,63 +103,13 @@
*
* <p>The default constraints are documented in {@link #constraints}
*
- * <p>Mutually exclusive with the following other properties defining constraints:
- *
- * <ul>
- * <li>constraints
- * <li>allow
- * <li>disallow
- * </ul>
- *
- * <p>If nothing is specified for constraints the default is the default for {@link #constraints}.
+ * <p>Mutually exclusive with the property `constraints` also defining constraints.
*
* @return Additional usage constraints for the target.
*/
KeepConstraint[] constraintAdditions() default {};
/**
- * Define the constraints that are allowed to be modified.
- *
- * <p>The specified option constraints do not need to be preserved for the target.
- *
- * <p>Mutually exclusive with the following other properties defining constraints:
- *
- * <ul>
- * <li>constraints
- * <li>constraintAdditions
- * <li>disallow
- * </ul>
- *
- * <p>If nothing is specified for constraints the default is the default for {@link #constraints}.
- *
- * @return Option constraints allowed to be modified for the target.
- * @deprecated Use {@link #constraints} instead.
- */
- @Deprecated
- KeepOption[] allow() default {};
-
- /**
- * Define the constraints that are not allowed to be modified.
- *
- * <p>The specified option constraints *must* be preserved for the target.
- *
- * <p>Mutually exclusive with the following other properties defining constraints:
- *
- * <ul>
- * <li>constraints
- * <li>constraintAdditions
- * <li>allow
- * </ul>
- *
- * <p>If nothing is specified for constraints the default is the default for {@link #constraints}.
- *
- * @return Option constraints not allowed to be modified for the target.
- * @deprecated Use {@link #constraints} instead.
- */
- @Deprecated
- KeepOption[] disallow() default {};
-
- /**
* Define the class pattern by reference to a binding.
*
* <p>Mutually exclusive with the following other properties defining class:
@@ -163,8 +122,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classAnnotatedByClassName
* <li>classAnnotatedByClassConstant
* <li>classAnnotatedByClassNamePattern
@@ -236,8 +193,6 @@
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -259,8 +214,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassConstant
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -279,8 +232,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -302,8 +253,6 @@
* <li>instanceOfClassName
* <li>instanceOfClassNameExclusive
* <li>instanceOfClassConstant
- * <li>extendsClassName
- * <li>extendsClassConstant
* <li>classFromBinding
* </ul>
*
@@ -314,56 +263,6 @@
Class<?> instanceOfClassConstantExclusive() default Object.class;
/**
- * Define the instance-of pattern as classes extending the fully qualified class name.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassConstant
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class name that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassName} instead.
- */
- @Deprecated
- String extendsClassName() default "";
-
- /**
- * Define the instance-of pattern as classes extending the referenced Class constant.
- *
- * <p>The pattern is exclusive in that it does not match classes that are instances of the
- * pattern, but only those that are instances of classes that are subclasses of the pattern.
- *
- * <p>Mutually exclusive with the following other properties defining instance-of:
- *
- * <ul>
- * <li>instanceOfClassName
- * <li>instanceOfClassNameExclusive
- * <li>instanceOfClassConstant
- * <li>instanceOfClassConstantExclusive
- * <li>extendsClassName
- * <li>classFromBinding
- * </ul>
- *
- * <p>If none are specified the default is to match any class instance.
- *
- * @return The class constant that defines what the class must extend.
- * @deprecated This property is deprecated, use {@link #instanceOfClassConstant} instead.
- */
- @Deprecated
- Class<?> extendsClassConstant() default Object.class;
-
- /**
* Define the class-annotated-by pattern by fully qualified class name.
*
* <p>Mutually exclusive with the following other properties defining class-annotated-by:
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByNative.java b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByNative.java
index b547778..2bcf8dd 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByNative.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByNative.java
@@ -83,15 +83,32 @@
*
* <p>The specified constraints must remain valid for the target.
*
- * <p>The default constraints depend on the type of the target.
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
*
* <ul>
- * <li>For classes, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#CLASS_INSTANTIATE}}
- * <li>For methods, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#METHOD_INVOKE}}
- * <li>For fields, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#FIELD_GET}, {@link KeepConstraint#FIELD_SET}}
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
+ * </ul>
+ *
+ * <p>For classes the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
+ * </ul>
+ *
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
* </ul>
*
* @return Usage constraints for the target.
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByReflection.java b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByReflection.java
index a139965..7133e96 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByReflection.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/annotations/UsedByReflection.java
@@ -83,15 +83,32 @@
*
* <p>The specified constraints must remain valid for the target.
*
- * <p>The default constraints depend on the type of the target.
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
*
* <ul>
- * <li>For classes, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#CLASS_INSTANTIATE}}
- * <li>For methods, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#METHOD_INVOKE}}
- * <li>For fields, the default is {{@link KeepConstraint#LOOKUP}, {@link KeepConstraint#NAME},
- * {@link KeepConstraint#FIELD_GET}, {@link KeepConstraint#FIELD_SET}}
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
+ * </ul>
+ *
+ * <p>For classes the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
+ * </ul>
+ *
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
* </ul>
*
* @return Usage constraints for the target.
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/asm/ConstraintsParser.java b/src/keepanno/java/com/android/tools/r8/keepanno/asm/ConstraintsParser.java
index 05b9fe8..e89279b 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/asm/ConstraintsParser.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/asm/ConstraintsParser.java
@@ -7,7 +7,6 @@
import com.android.tools.r8.keepanno.asm.ConstraintsParser.ConstraintsProperty;
import com.android.tools.r8.keepanno.ast.AnnotationConstants.Target;
import com.android.tools.r8.keepanno.ast.KeepConstraints;
-import com.android.tools.r8.keepanno.ast.KeepOptions;
import com.android.tools.r8.keepanno.ast.ParsingContext;
import java.util.function.Consumer;
import org.objectweb.asm.AnnotationVisitor;
@@ -16,9 +15,7 @@
public enum ConstraintsProperty {
CONSTRAINTS,
- ADDITIONS,
- ALLOW,
- DISALLOW
+ ADDITIONS
}
public ConstraintsParser(ParsingContext parsingContext) {
@@ -36,20 +33,6 @@
constraints -> setValue.accept(KeepConstraints.defaultAdditions(constraints)));
case CONSTRAINTS:
return new KeepConstraintsVisitor(parsingContext, setValue::accept);
- case ALLOW:
- return new KeepOptionsVisitor(
- parsingContext,
- options ->
- setValue.accept(
- KeepConstraints.fromLegacyOptions(
- KeepOptions.allowBuilder().addAll(options).build())));
- case DISALLOW:
- return new KeepOptionsVisitor(
- parsingContext,
- options ->
- setValue.accept(
- KeepConstraints.fromLegacyOptions(
- KeepOptions.disallowBuilder().addAll(options).build())));
default:
return null;
}
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepEdgeReader.java b/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepEdgeReader.java
index b37f18f..8c85b9a 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepEdgeReader.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepEdgeReader.java
@@ -748,8 +748,6 @@
constraintsParser = new ConstraintsParser(parsingContext);
constraintsParser.setProperty(Target.constraints, ConstraintsProperty.CONSTRAINTS);
constraintsParser.setProperty(Target.constraintAdditions, ConstraintsProperty.ADDITIONS);
- constraintsParser.setProperty(Target.allow, ConstraintsProperty.ALLOW);
- constraintsParser.setProperty(Target.disallow, ConstraintsProperty.DISALLOW);
}
@Override
@@ -859,8 +857,6 @@
constraintsParser = new ConstraintsParser(parsingContext);
constraintsParser.setProperty(Target.constraints, ConstraintsProperty.CONSTRAINTS);
constraintsParser.setProperty(Target.constraintAdditions, ConstraintsProperty.ADDITIONS);
- constraintsParser.setProperty(Target.allow, ConstraintsProperty.ALLOW);
- constraintsParser.setProperty(Target.disallow, ConstraintsProperty.DISALLOW);
}
@Override
@@ -1211,8 +1207,6 @@
Item.instanceOfClassNameExclusive, InstanceOfProperties.NAME_EXCL);
instanceOfParser.setProperty(
Item.instanceOfClassConstantExclusive, InstanceOfProperties.CONSTANT_EXCL);
- instanceOfParser.setProperty(Item.extendsClassName, InstanceOfProperties.NAME_EXCL);
- instanceOfParser.setProperty(Item.extendsClassConstant, InstanceOfProperties.CONSTANT_EXCL);
parsers = ImmutableList.of(classNameParser, annotatedByParser, instanceOfParser);
}
@@ -1812,8 +1806,6 @@
optionsParser = new ConstraintsParser(parsingContext);
optionsParser.setProperty(Target.constraints, ConstraintsProperty.CONSTRAINTS);
optionsParser.setProperty(Target.constraintAdditions, ConstraintsProperty.ADDITIONS);
- optionsParser.setProperty(Target.allow, ConstraintsProperty.ALLOW);
- optionsParser.setProperty(Target.disallow, ConstraintsProperty.DISALLOW);
}
@Override
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepOptionsVisitor.java b/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepOptionsVisitor.java
deleted file mode 100644
index b369d2d..0000000
--- a/src/keepanno/java/com/android/tools/r8/keepanno/asm/KeepOptionsVisitor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.keepanno.asm;
-
-import com.android.tools.r8.keepanno.asm.KeepEdgeReader.Parent;
-import com.android.tools.r8.keepanno.ast.AnnotationConstants;
-import com.android.tools.r8.keepanno.ast.AnnotationConstants.Option;
-import com.android.tools.r8.keepanno.ast.KeepOptions.KeepOption;
-import com.android.tools.r8.keepanno.ast.ParsingContext;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-public class KeepOptionsVisitor extends AnnotationVisitorBase {
-
- private final Parent<Collection<KeepOption>> parent;
- private final Set<KeepOption> options = new HashSet<>();
-
- public KeepOptionsVisitor(ParsingContext parsingContext, Parent<Collection<KeepOption>> parent) {
- super(parsingContext);
- this.parent = parent;
- }
-
- @Override
- public void visitEnum(String ignore, String descriptor, String value) {
- if (!descriptor.equals(AnnotationConstants.Option.DESCRIPTOR)) {
- super.visitEnum(ignore, descriptor, value);
- }
- KeepOption option;
- switch (value) {
- case Option.SHRINKING:
- option = KeepOption.SHRINKING;
- break;
- case Option.OPTIMIZATION:
- option = KeepOption.OPTIMIZING;
- break;
- case Option.OBFUSCATION:
- option = KeepOption.OBFUSCATING;
- break;
- case Option.ACCESS_MODIFICATION:
- option = KeepOption.ACCESS_MODIFICATION;
- break;
- case Option.ANNOTATION_REMOVAL:
- option = KeepOption.ANNOTATION_REMOVAL;
- break;
- default:
- super.visitEnum(ignore, descriptor, value);
- return;
- }
- options.add(option);
- }
-
- @Override
- public void visitEnd() {
- parent.accept(options);
- super.visitEnd();
- }
-}
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/ast/AnnotationConstants.java b/src/keepanno/java/com/android/tools/r8/keepanno/ast/AnnotationConstants.java
index a03cb6c..9828d43 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/ast/AnnotationConstants.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/ast/AnnotationConstants.java
@@ -79,8 +79,6 @@
public static final String instanceOfClassConstant = "instanceOfClassConstant";
public static final String instanceOfClassConstantExclusive =
"instanceOfClassConstantExclusive";
- public static final String extendsClassName = "extendsClassName";
- public static final String extendsClassConstant = "extendsClassConstant";
public static final String classAnnotatedByGroup = "class-annotated-by";
public static final String classAnnotatedByClassName = "classAnnotatedByClassName";
public static final String classAnnotatedByClassConstant = "classAnnotatedByClassConstant";
@@ -141,8 +139,6 @@
public static final String constraintsGroup = "constraints";
public static final String constraints = "constraints";
public static final String constraintAdditions = "constraintAdditions";
- public static final String allow = "allow";
- public static final String disallow = "disallow";
}
public static final class Kind {
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepConstraints.java b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepConstraints.java
index a4be849..c319a3c 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepConstraints.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepConstraints.java
@@ -14,10 +14,6 @@
public abstract class KeepConstraints {
- public static KeepConstraints fromLegacyOptions(KeepOptions options) {
- return new LegacyOptions(options);
- }
-
public static KeepConstraints defaultConstraints() {
return Defaults.INSTANCE;
}
@@ -46,31 +42,6 @@
}
}
- private static class LegacyOptions extends KeepConstraints {
-
- private final KeepOptions options;
-
- private LegacyOptions(KeepOptions options) {
- this.options = options;
- }
-
- @Override
- public String toString() {
- return options.toString();
- }
-
- @Override
- public KeepOptions convertToKeepOptions(KeepOptions defaultOptions) {
- return options;
- }
-
- @Override
- public Set<KeepAttribute> getRequiredKeepAttributes() {
- // The legacy option specification does not have any implicit/required attributes.
- return Collections.emptySet();
- }
- }
-
private static class Defaults extends KeepConstraints {
private static final Defaults INSTANCE = new Defaults();
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepTarget.java b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepTarget.java
index e6bcf49..8367dfe 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepTarget.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepTarget.java
@@ -23,10 +23,6 @@
return setItemReference(itemPattern.toItemReference());
}
- public Builder setOptions(KeepOptions options) {
- return setConstraints(KeepConstraints.fromLegacyOptions(options));
- }
-
public Builder setConstraints(KeepConstraints constraints) {
this.constraints = constraints;
return this;
diff --git a/src/test/java/com/android/tools/r8/keepanno/KeepInvalidTargetTest.java b/src/test/java/com/android/tools/r8/keepanno/KeepInvalidTargetTest.java
index b3baa2e..0eace48 100644
--- a/src/test/java/com/android/tools/r8/keepanno/KeepInvalidTargetTest.java
+++ b/src/test/java/com/android/tools/r8/keepanno/KeepInvalidTargetTest.java
@@ -12,7 +12,7 @@
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.keepanno.annotations.KeepOption;
+import com.android.tools.r8.keepanno.annotations.KeepConstraint;
import com.android.tools.r8.keepanno.annotations.KeepTarget;
import com.android.tools.r8.keepanno.annotations.StringPattern;
import com.android.tools.r8.keepanno.annotations.UsesReflection;
@@ -100,24 +100,24 @@
}
@Test
- public void testInvalidExtendsDecl() {
+ public void testInvalidInstanceOfDecl() {
assertThrowsWith(
- () -> extractRuleForClass(MultipleExtendsDeclarations.class),
+ () -> extractRuleForClass(MultipleInstanceOfDeclarations.class),
allOf(
containsString("Multiple properties"),
- containsString("extendsClassName"),
- containsString("extendsClassConstant"),
+ containsString("instanceOfClassName"),
+ containsString("instanceOfClassConstant"),
containsString("at property-group: instance-of"),
containsString("at annotation: @UsesReflection"),
containsString("at method: void main")));
}
- static class MultipleExtendsDeclarations {
+ static class MultipleInstanceOfDeclarations {
@UsesReflection(
@KeepTarget(
- extendsClassName = "foo",
- extendsClassConstant = MultipleClassDeclarations.class))
+ instanceOfClassName = "foo",
+ instanceOfClassConstant = MultipleClassDeclarations.class))
public static void main(String[] args) {
System.out.println("Hello, world");
}
@@ -144,21 +144,21 @@
@Test
public void testInvalidOptionsDecl() {
assertThrowsWith(
- () -> extractRuleForClass(MultipleOptionDeclarations.class),
+ () -> extractRuleForClass(MultipleConstraintDeclarations.class),
allOf(
containsString("Multiple properties"),
- containsString("allow"),
- containsString("disallow"),
+ containsString("constraints"),
+ containsString("constraintAdditions"),
containsString("at property-group: constraints")));
}
- static class MultipleOptionDeclarations {
+ static class MultipleConstraintDeclarations {
@UsesReflection(
@KeepTarget(
classConstant = A.class,
- allow = {KeepOption.OPTIMIZATION},
- disallow = {KeepOption.SHRINKING}))
+ constraints = {KeepConstraint.LOOKUP},
+ constraintAdditions = {KeepConstraint.NAME}))
public static void main(String[] args) {
System.out.println("Hello, world");
}
diff --git a/src/test/java/com/android/tools/r8/keepanno/ast/KeepEdgeAstTest.java b/src/test/java/com/android/tools/r8/keepanno/ast/KeepEdgeAstTest.java
index c504c4a..d2deccb 100644
--- a/src/test/java/com/android/tools/r8/keepanno/ast/KeepEdgeAstTest.java
+++ b/src/test/java/com/android/tools/r8/keepanno/ast/KeepEdgeAstTest.java
@@ -9,7 +9,6 @@
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.keepanno.ast.KeepBindings.KeepBindingSymbol;
-import com.android.tools.r8.keepanno.ast.KeepOptions.KeepOption;
import com.android.tools.r8.keepanno.keeprules.KeepRuleExtractor;
import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.ImmutableList;
@@ -59,8 +58,14 @@
}
@Test
- public void testSoftPinViaDisallow() {
- KeepOptions disallowOptions = KeepOptions.disallow(KeepOption.OPTIMIZING);
+ public void testSoftPinViaConstraints() {
+ KeepConstraints constraints =
+ KeepConstraints.builder()
+ .add(KeepConstraint.classInstantiate())
+ .add(KeepConstraint.methodInvoke())
+ .add(KeepConstraint.fieldGet())
+ .add(KeepConstraint.fieldSet())
+ .build();
KeepEdge edge =
KeepEdge.builder()
.setConsequences(
@@ -68,16 +73,17 @@
.addTarget(
KeepTarget.builder()
.setItemPattern(KeepItemPattern.anyClass())
- .setOptions(disallowOptions)
+ .setConstraints(constraints)
.build())
.addTarget(
KeepTarget.builder()
.setItemPattern(KeepItemPattern.anyMember())
- .setOptions(disallowOptions)
+ .setConstraints(constraints)
.build())
.build())
.build();
- // Disallow will issue the full inverse of the known options, e.g., 'allowaccessmodification'.
+ // Pinning just the use constraints points will issue the full inverse of the known options,
+ // e.g., 'allowaccessmodification'.
List<String> options = ImmutableList.of("shrinking", "obfuscation", "accessmodification");
String allows = String.join(",allow", options);
// The "any" item will be split in two rules, one for the targeted types and one for the
@@ -88,34 +94,6 @@
"-keepclassmembers,allow" + allows + " class ** { *; }"),
extract(edge));
}
-
- @Test
- public void testSoftPinViaAllow() {
- KeepOptions allowOptions = KeepOptions.allow(KeepOption.OBFUSCATING, KeepOption.SHRINKING);
- KeepEdge edge =
- KeepEdge.builder()
- .setConsequences(
- KeepConsequences.builder()
- .addTarget(
- KeepTarget.builder()
- .setItemPattern(KeepItemPattern.anyClass())
- .setOptions(allowOptions)
- .build())
- .addTarget(
- KeepTarget.builder()
- .setItemPattern(KeepItemPattern.anyMember())
- .setOptions(allowOptions)
- .build())
- .build())
- .build();
- // Allow is just the ordered list of options.
- assertEquals(
- StringUtils.unixLines(
- "-keep,allowshrinking,allowobfuscation class ** { void finalize(); }",
- "-keepclassmembers,allowshrinking,allowobfuscation class ** { *; }"),
- extract(edge));
- }
-
@Test
public void testKeepClass() {
KeepTarget target = target(classItem(CLASS));
diff --git a/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java b/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
index 6344760..c6bb24b 100644
--- a/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
+++ b/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
@@ -488,34 +488,7 @@
}
private Group getKeepConstraintsGroup() {
- return new Group(CONSTRAINTS_GROUP)
- .addMember(constraints())
- .addMember(constraintAdditions())
- .addMember(
- new GroupMember("allow")
- .setDeprecated("Use " + docLink(constraints()) + " instead.")
- .setDocTitle(
- "Define the " + CONSTRAINTS_GROUP + " that are allowed to be modified.")
- .addParagraph(
- "The specified option constraints do not need to be preserved for the"
- + " target.")
- .setDocReturn("Option constraints allowed to be modified for the target.")
- .defaultArrayEmpty(KeepOption.class))
- .addMember(
- new GroupMember("disallow")
- .setDeprecated("Use " + docLink(constraints()) + " instead.")
- .setDocTitle(
- "Define the " + CONSTRAINTS_GROUP + " that are not allowed to be modified.")
- .addParagraph(
- "The specified option constraints *must* be preserved for the target.")
- .setDocReturn("Option constraints not allowed to be modified for the target.")
- .defaultArrayEmpty(KeepOption.class))
- .addDocFooterParagraph(
- "If nothing is specified for "
- + CONSTRAINTS_GROUP
- + " the default is the default for "
- + docLink(constraints())
- + ".");
+ return new Group(CONSTRAINTS_GROUP).addMember(constraints()).addMember(constraintAdditions());
}
private static String docLinkList(Enum<?>... values) {
@@ -526,20 +499,19 @@
return new GroupMember("constraints")
.setDocTitle("Define the usage constraints of the target.")
.addParagraph("The specified constraints must remain valid for the target.")
- .addParagraph("The default constraints depend on the type of the target.")
+ .addParagraph(
+ "The default constraints depend on the kind of the target.",
+ "For all targets the default constraints include:")
.addUnorderedList(
- "For classes, the default is "
- + docLinkList(
- KeepConstraint.LOOKUP, KeepConstraint.NAME, KeepConstraint.CLASS_INSTANTIATE),
- "For methods, the default is "
- + docLinkList(
- KeepConstraint.LOOKUP, KeepConstraint.NAME, KeepConstraint.METHOD_INVOKE),
- "For fields, the default is "
- + docLinkList(
- KeepConstraint.LOOKUP,
- KeepConstraint.NAME,
- KeepConstraint.FIELD_GET,
- KeepConstraint.FIELD_SET))
+ docLink(KeepConstraint.LOOKUP),
+ docLink(KeepConstraint.NAME),
+ docLink(KeepConstraint.VISIBILITY_RELAX))
+ .addParagraph("For classes the default constraints also include:")
+ .addUnorderedList(docLink(KeepConstraint.CLASS_INSTANTIATE))
+ .addParagraph("For methods the default constraints also include:")
+ .addUnorderedList(docLink(KeepConstraint.METHOD_INVOKE))
+ .addParagraph("For fields the default constraints also include:")
+ .addUnorderedList(docLink(KeepConstraint.FIELD_GET), docLink(KeepConstraint.FIELD_SET))
.setDocReturn("Usage constraints for the target.")
.defaultArrayEmpty(KeepConstraint.class);
}
@@ -657,42 +629,12 @@
.defaultObjectClass();
}
- private GroupMember extendsClassName() {
- return new GroupMember("extendsClassName")
- .setDocTitle(
- "Define the "
- + INSTANCE_OF_GROUP
- + " pattern as classes extending the fully qualified class name.")
- .addParagraph(getInstanceOfExclusiveDoc())
- .setDeprecated(
- "This property is deprecated, use " + docLink(instanceOfClassName()) + " instead.")
- .setDocReturn("The class name that defines what the class must extend.")
- .defaultEmptyString();
- }
-
- private GroupMember extendsClassConstant() {
- return new GroupMember("extendsClassConstant")
- .setDocTitle(
- "Define the "
- + INSTANCE_OF_GROUP
- + " pattern as classes extending the referenced Class constant.")
- .addParagraph(getInstanceOfExclusiveDoc())
- .setDeprecated(
- "This property is deprecated, use "
- + docLink(instanceOfClassConstant())
- + " instead.")
- .setDocReturn("The class constant that defines what the class must extend.")
- .defaultObjectClass();
- }
-
private Group createClassInstanceOfPatternGroup() {
return new Group(INSTANCE_OF_GROUP)
.addMember(instanceOfClassName())
.addMember(instanceOfClassNameExclusive())
.addMember(instanceOfClassConstant())
.addMember(instanceOfClassConstantExclusive())
- .addMember(extendsClassName())
- .addMember(extendsClassConstant())
.addDocFooterParagraph(
"If none are specified the default is to match any class instance.");
}