summaryrefslogtreecommitdiff
path: root/tools/processors
diff options
context:
space:
mode:
authorAshley Rose <ashleyrose@google.com>2019-03-20 15:18:25 -0400
committerAshley Rose <ashleyrose@google.com>2019-03-20 15:24:28 -0400
commitb948bcd44de5afc72a498a8c367a7a15fd4c580b (patch)
treee95cdb29c951c69d32d07bff51626150f0d2ccdd /tools/processors
parentcf49db1265539c41931306a2d797e2f72d8e9611 (diff)
Remove unused @InspectableNodeName
Change-Id: Ib5a2688e7b25c4c8ba43dc4aeb80e17a12427f9c Fix: 128997046 Test: atest --host view-inspector-annotation-processor-test
Diffstat (limited to 'tools/processors')
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java10
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java79
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java7
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java27
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java34
-rw-r--r--tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java44
-rw-r--r--tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java7
-rw-r--r--tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt37
8 files changed, 17 insertions, 228 deletions
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
index 147f054b1abb..04710e436ffb 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
@@ -39,7 +39,6 @@ import java.util.Optional;
public final class InspectableClassModel {
private final @NonNull ClassName mClassName;
private final @NonNull Map<String, Property> mPropertyMap;
- private @NonNull Optional<String> mNodeName = Optional.empty();
/**
* @param className The name of the modeled class
@@ -54,15 +53,6 @@ public final class InspectableClassModel {
return mClassName;
}
- @NonNull
- public Optional<String> getNodeName() {
- return mNodeName;
- }
-
- public void setNodeName(@NonNull Optional<String> nodeName) {
- mNodeName = nodeName;
- }
-
/**
* Add a property to the model, replacing an existing property of the same name.
*
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java
deleted file mode 100644
index 64a60fbc9179..000000000000
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2019 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.processor.view.inspector;
-
-import androidx.annotation.NonNull;
-
-import java.util.Optional;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-
-/**
- * Process {@code @InspectableNodeName} annotations.
- *
- * @see android.view.inspector.InspectableNodeName
- */
-public final class InspectableNodeNameProcessor implements ModelProcessor {
- private final @NonNull String mQualifiedName;
- private final @NonNull ProcessingEnvironment mProcessingEnv;
- private final @NonNull AnnotationUtils mAnnotationUtils;
-
- /**
- * @param annotationQualifiedName The qualified name of the annotation to process
- * @param processingEnv The processing environment from the parent processor
- */
- public InspectableNodeNameProcessor(
- @NonNull String annotationQualifiedName,
- @NonNull ProcessingEnvironment processingEnv) {
- mQualifiedName = annotationQualifiedName;
- mProcessingEnv = processingEnv;
- mAnnotationUtils = new AnnotationUtils(processingEnv);
- }
-
- /**
- * Set the node name on the model if one is supplied.
- *
- * If the model already has a different node name, the node name will not be updated, and
- * the processor will print an error the the messager.
- *
- * @param element The annotated element to operate on
- * @param model The model this element should be merged into
- */
- @Override
- public void process(@NonNull Element element, @NonNull InspectableClassModel model) {
- try {
- final AnnotationMirror mirror =
- mAnnotationUtils.exactlyOneMirror(mQualifiedName, element);
- final Optional<String> nodeName = mAnnotationUtils
- .typedValueByName("value", String.class, element, mirror);
-
- if (!model.getNodeName().isPresent() || model.getNodeName().equals(nodeName)) {
- model.setNodeName(nodeName);
- } else {
- final String message = String.format(
- "Node name was already set to \"%s\", refusing to change it to \"%s\".",
- model.getNodeName().get(),
- nodeName);
- throw new ProcessingException(message, element, mirror);
- }
- } catch (ProcessingException processingException) {
- processingException.print(mProcessingEnv.getMessager());
- }
- }
-}
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
index 7f5f9ca8a8f8..2bd867c235c7 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
@@ -46,7 +46,7 @@ import javax.lang.model.type.TypeMirror;
*
* @see android.view.inspector.InspectableProperty
*/
-public final class InspectablePropertyProcessor implements ModelProcessor {
+public final class InspectablePropertyProcessor {
private final @NonNull String mQualifiedName;
private final @NonNull ProcessingEnvironment mProcessingEnv;
private final @NonNull AnnotationUtils mAnnotationUtils;
@@ -139,7 +139,6 @@ public final class InspectablePropertyProcessor implements ModelProcessor {
mAnnotationUtils = new AnnotationUtils(processingEnv);
}
- @Override
public void process(@NonNull Element element, @NonNull InspectableClassModel model) {
try {
final AnnotationMirror annotation =
@@ -608,7 +607,7 @@ public final class InspectablePropertyProcessor implements ModelProcessor {
* Build a model of an {@code int} enumeration mapping from annotation values.
*
* This method only handles the one-to-one mapping of mirrors of
- * {@link android.view.inspector.InspectableProperty.EnumMap} annotations into
+ * {@link android.view.inspector.InspectableProperty.EnumEntry} annotations into
* {@link IntEnumEntry} objects. Further validation should be handled elsewhere
*
* @see android.view.inspector.InspectableProperty#enumMapping()
@@ -656,7 +655,7 @@ public final class InspectablePropertyProcessor implements ModelProcessor {
* Build a model of an {@code int} flag mapping from annotation values.
*
* This method only handles the one-to-one mapping of mirrors of
- * {@link android.view.inspector.InspectableProperty.FlagMap} annotations into
+ * {@link android.view.inspector.InspectableProperty.FlagEntry} annotations into
* {@link IntFlagEntry} objects. Further validation should be handled elsewhere
*
* @see android.view.inspector.IntFlagMapping
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
index c428a4613c95..6e38c245c70e 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
@@ -163,8 +163,6 @@ public final class InspectionCompanionGenerator {
.addMethod(generateMapProperties(properties, fields))
.addMethod(generateReadProperties(properties, fields, model.getClassName()));
- model.getNodeName().ifPresent(name -> builder.addMethod(generateGetNodeName(name)));
-
return builder.build();
}
@@ -451,31 +449,6 @@ public final class InspectionCompanionGenerator {
}
/**
- * Generate an implementation of
- * {@link android.view.inspector.InspectionCompanion#getNodeName()}.
- *
- * Example:
- * <pre>
- * @Override
- * public String getNodeName() {
- * return "nodeName";
- * }
- * </pre>
- *
- * @param nodeName The name of this node
- * @return A method definition that returns the node name
- */
- @NonNull
- private MethodSpec generateGetNodeName(@NonNull String nodeName) {
- return MethodSpec.methodBuilder("getNodeName")
- .addAnnotation(Override.class)
- .addModifiers(Modifier.PUBLIC)
- .returns(String.class)
- .addStatement("return $S", nodeName)
- .build();
- }
-
- /**
* Generate the final class name for the inspection companion from the model's class name.
*
* The generated class is added to the same package as the source class. If the class in the
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java
deleted file mode 100644
index ab38f4c9e1b0..000000000000
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2019 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.processor.view.inspector;
-
-import androidx.annotation.NonNull;
-
-import javax.lang.model.element.Element;
-
-/**
- * An interface for annotation processors that operate on a single element and a class model.
- */
-public interface ModelProcessor {
- /**
- * Process the supplied element, mutating the model as needed.
- *
- * @param element The annotated element to operate on
- * @param model The model this element should be merged into
- */
- void process(@NonNull Element element, @NonNull InspectableClassModel model);
-}
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
index d9ed1fb9f343..80d37273b422 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
@@ -38,25 +38,18 @@ import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
-
/**
* An annotation processor for the platform inspectable annotations.
*
- * It mostly delegates to {@link ModelProcessor} and {@link InspectionCompanionGenerator}. This
- * modular architecture allows the core generation code to be reused for comparable annotations
- * outside the platform, such as in AndroidX.
+ * It mostly delegates to {@link InspectablePropertyProcessor} and
+ * {@link InspectionCompanionGenerator}. This modular architecture allows the core generation code
+ * to be reused for comparable annotations outside the platform.
*
- * @see android.view.inspector.InspectableNodeName
* @see android.view.inspector.InspectableProperty
*/
-@SupportedAnnotationTypes({
- PlatformInspectableProcessor.NODE_NAME_QUALIFIED_NAME,
- PlatformInspectableProcessor.PROPERTY_QUALIFIED_NAME
-})
+@SupportedAnnotationTypes({PlatformInspectableProcessor.ANNOTATION_QUALIFIED_NAME})
public final class PlatformInspectableProcessor extends AbstractProcessor {
- static final String NODE_NAME_QUALIFIED_NAME =
- "android.view.inspector.InspectableNodeName";
- static final String PROPERTY_QUALIFIED_NAME =
+ static final String ANNOTATION_QUALIFIED_NAME =
"android.view.inspector.InspectableProperty";
@Override
@@ -71,18 +64,8 @@ public final class PlatformInspectableProcessor extends AbstractProcessor {
final Map<String, InspectableClassModel> modelMap = new HashMap<>();
for (TypeElement annotation : annotations) {
- if (annotation.getQualifiedName().contentEquals(NODE_NAME_QUALIFIED_NAME)) {
- runModelProcessor(
- roundEnv.getElementsAnnotatedWith(annotation),
- new InspectableNodeNameProcessor(NODE_NAME_QUALIFIED_NAME, processingEnv),
- modelMap);
-
- } else if (annotation.getQualifiedName().contentEquals(PROPERTY_QUALIFIED_NAME)) {
- runModelProcessor(
- roundEnv.getElementsAnnotatedWith(annotation),
- new InspectablePropertyProcessor(PROPERTY_QUALIFIED_NAME, processingEnv),
- modelMap);
-
+ if (annotation.getQualifiedName().contentEquals(ANNOTATION_QUALIFIED_NAME)) {
+ processProperties(roundEnv.getElementsAnnotatedWith(annotation), modelMap);
} else {
fail("Unexpected annotation type", annotation);
}
@@ -106,16 +89,17 @@ public final class PlatformInspectableProcessor extends AbstractProcessor {
}
/**
- * Run a {@link ModelProcessor} for a set of elements
+ * Runs {@link PlatformInspectableProcessor} on a set of annotated elements.
*
- * @param elements Elements to process, should be annotated correctly
- * @param processor The processor to use
- * @param modelMap A map of qualified class names to models
+ * @param elements A set of annotated elements to process
+ * @param modelMap A map of qualified class names to class models to update
*/
- private void runModelProcessor(
+ private void processProperties(
@NonNull Set<? extends Element> elements,
- @NonNull ModelProcessor processor,
@NonNull Map<String, InspectableClassModel> modelMap) {
+ final InspectablePropertyProcessor processor =
+ new InspectablePropertyProcessor(ANNOTATION_QUALIFIED_NAME, processingEnv);
+
for (Element element : elements) {
final Optional<TypeElement> classElement = enclosingClassElement(element);
diff --git a/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java b/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
index 3ec620a1a4bf..c6e6018869ac 100644
--- a/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
+++ b/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
@@ -36,7 +36,6 @@ import org.junit.Test;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
-import java.util.Optional;
/**
* Tests for {@link InspectionCompanionGenerator}
@@ -56,12 +55,6 @@ public class InspectionCompanionGeneratorTest {
}
@Test
- public void testNodeName() {
- mModel.setNodeName(Optional.of("NodeName"));
- assertGeneratedFileEquals("NodeName");
- }
-
- @Test
public void testNestedClass() {
mModel = new InspectableClassModel(
ClassName.get("com.android.node", "Outer", "Inner"));
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt
deleted file mode 100644
index ffa1f0be02d4..000000000000
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.android.node;
-
-import android.view.inspector.InspectionCompanion;
-import android.view.inspector.PropertyMapper;
-import android.view.inspector.PropertyReader;
-import java.lang.Override;
-import java.lang.String;
-
-/**
- * Inspection companion for {@link TestNode}.
- *
- * Generated by {@link android.processor.view.inspector.InspectionCompanionGenerator}
- * on behalf of {@link android.processor.view.inspector.InspectionCompanionGeneratorTest}.
- */
-public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
- /**
- * Guards against reading properties before mapping them.
- */
- private boolean mPropertiesMapped = false;
-
- @Override
- public void mapProperties(PropertyMapper propertyMapper) {
- mPropertiesMapped = true;
- }
-
- @Override
- public void readProperties(TestNode node, PropertyReader propertyReader) {
- if (!mPropertiesMapped) {
- throw new InspectionCompanion.UninitializedPropertyMapException();
- }
- }
-
- @Override
- public String getNodeName() {
- return "NodeName";
- }
-}