summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathew Inwood <mathewi@google.com>2018-11-23 14:57:28 +0000
committerMathew Inwood <mathewi@google.com>2018-12-20 07:47:29 +0000
commitcfc7952cc8649a1b2418f6502f40cef32487464f (patch)
treeef3a4ad7adf71ed67ae16ad2e18607be320b37ff
parenta89f04a7421a519e2625959fa474b5cf2bcca083 (diff)
Include annotation property values in output.
When editing annotations, we want the ability *not* to overwrite any existing annotation properties already in place. Include any properties set on the annotation in the output, so that the edit_annotations script can know that they're there. The annotation properties are encoded like URL query parameters for convenience; it makes them easy to encode here & subsequently decode on the other side (in Python). Test: m framework-annotation-proc & inspect output. (cherry picked from commit bd7077065c211f49b090aa4250b53b58461adfd9) Merged-In: I71fb1215ad2790751be336b4955c163bb323a4a6 Change-Id: I0b33e2b379076346ce258d93a9225a9143b7d91a
-rw-r--r--tools/processors/unsupportedappusage/src/android/processor/unsupportedappusage/UnsupportedAppUsageProcessor.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/processors/unsupportedappusage/src/android/processor/unsupportedappusage/UnsupportedAppUsageProcessor.java b/tools/processors/unsupportedappusage/src/android/processor/unsupportedappusage/UnsupportedAppUsageProcessor.java
index 1d4c435939db..d368136c7081 100644
--- a/tools/processors/unsupportedappusage/src/android/processor/unsupportedappusage/UnsupportedAppUsageProcessor.java
+++ b/tools/processors/unsupportedappusage/src/android/processor/unsupportedappusage/UnsupportedAppUsageProcessor.java
@@ -28,6 +28,7 @@ import com.sun.tools.javac.util.Position;
import java.io.IOException;
import java.io.PrintStream;
+import java.net.URLEncoder;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -38,7 +39,9 @@ import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
/**
@@ -108,10 +111,25 @@ public class UnsupportedAppUsageProcessor extends AbstractProcessor {
"startline",
"startcol",
"endline",
- "endcol"
+ "endcol",
+ "properties"
);
}
+ private String encodeAnnotationProperties(AnnotationMirror annotation) {
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e
+ : annotation.getElementValues().entrySet()) {
+ if (sb.length() > 0) {
+ sb.append("&");
+ }
+ sb.append(e.getKey().getSimpleName())
+ .append("=")
+ .append(URLEncoder.encode(e.getValue().toString()));
+ }
+ return sb.toString();
+ }
+
/**
* Maps an annotated element to the source position of the @UnsupportedAppUsage annotation
* attached to it. It returns CSV in the format:
@@ -137,7 +155,8 @@ public class UnsupportedAppUsageProcessor extends AbstractProcessor {
lines.getLineNumber(pair.fst.pos().getStartPosition()),
lines.getColumnNumber(pair.fst.pos().getStartPosition()),
lines.getLineNumber(pair.fst.pos().getEndPosition(pair.snd.endPositions)),
- lines.getColumnNumber(pair.fst.pos().getEndPosition(pair.snd.endPositions)));
+ lines.getColumnNumber(pair.fst.pos().getEndPosition(pair.snd.endPositions)),
+ encodeAnnotationProperties(unsupportedAppUsage));
}
/**