diff options
author | clshepherd <clshepherd@google.com> | 2019-10-11 09:03:01 -0700 |
---|---|---|
committer | Kurt Alfred Kluever <kak@google.com> | 2019-10-14 11:56:52 -0400 |
commit | 78eef202297404a65d4e4745315aa1c0b0efb3a7 (patch) | |
tree | f0e884e5f8f1f226e0cf39a1b615d5a47c1a65e3 /common | |
parent | 4543619f73dc94cc9a7232f340067e5bfe8ddb24 (diff) | |
download | auto-78eef202297404a65d4e4745315aa1c0b0efb3a7.tar.gz |
Fix 4 ErrorProneStyle findings:
* Constructors and methods with the same name should appear sequentially with no other code in between. Please re-order or re-name methods.
* These grouping parentheses are unnecessary; it is unlikely the code will be misinterpreted without them
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=274183390
Diffstat (limited to 'common')
3 files changed, 38 insertions, 45 deletions
diff --git a/common/src/main/java/com/google/auto/common/BasicAnnotationProcessor.java b/common/src/main/java/com/google/auto/common/BasicAnnotationProcessor.java index 8de3b817..be4c3766 100644 --- a/common/src/main/java/com/google/auto/common/BasicAnnotationProcessor.java +++ b/common/src/main/java/com/google/auto/common/BasicAnnotationProcessor.java @@ -189,9 +189,33 @@ public abstract class BasicAnnotationProcessor extends AbstractProcessor { return false; } - /** - * Returns the previously deferred elements. - */ + /** Processes the valid elements, including those previously deferred by each step. */ + private void process(ImmutableSetMultimap<Class<? extends Annotation>, Element> validElements) { + for (ProcessingStep step : steps) { + ImmutableSetMultimap<Class<? extends Annotation>, Element> stepElements = + new ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element>() + .putAll(indexByAnnotation(elementsDeferredBySteps.get(step), step.annotations())) + .putAll(filterKeys(validElements, Predicates.<Object>in(step.annotations()))) + .build(); + if (stepElements.isEmpty()) { + elementsDeferredBySteps.removeAll(step); + } else { + Set<? extends Element> rejectedElements = step.process(stepElements); + elementsDeferredBySteps.replaceValues( + step, + transform( + rejectedElements, + new Function<Element, ElementName>() { + @Override + public ElementName apply(Element element) { + return ElementName.forAnnotatedElement(element); + } + })); + } + } + } + + /** Returns the previously deferred elements. */ private ImmutableMap<String, Optional<? extends Element>> deferredElements() { ImmutableMap.Builder<String, Optional<? extends Element>> deferredElements = ImmutableMap.builder(); @@ -320,32 +344,6 @@ public abstract class BasicAnnotationProcessor extends AbstractProcessor { return validElements.build(); } - /** Processes the valid elements, including those previously deferred by each step. */ - private void process(ImmutableSetMultimap<Class<? extends Annotation>, Element> validElements) { - for (ProcessingStep step : steps) { - ImmutableSetMultimap<Class<? extends Annotation>, Element> stepElements = - new ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element>() - .putAll(indexByAnnotation(elementsDeferredBySteps.get(step), step.annotations())) - .putAll(filterKeys(validElements, Predicates.<Object>in(step.annotations()))) - .build(); - if (stepElements.isEmpty()) { - elementsDeferredBySteps.removeAll(step); - } else { - Set<? extends Element> rejectedElements = step.process(stepElements); - elementsDeferredBySteps.replaceValues( - step, - transform( - rejectedElements, - new Function<Element, ElementName>() { - @Override - public ElementName apply(Element element) { - return ElementName.forAnnotatedElement(element); - } - })); - } - } - } - private ImmutableSetMultimap<Class<? extends Annotation>, Element> indexByAnnotation( Set<ElementName> annotatedElements, Set<? extends Class<? extends Annotation>> annotationClasses) { diff --git a/common/src/main/java/com/google/auto/common/GeneratedAnnotationSpecs.java b/common/src/main/java/com/google/auto/common/GeneratedAnnotationSpecs.java index e87d3675..bb35e22f 100644 --- a/common/src/main/java/com/google/auto/common/GeneratedAnnotationSpecs.java +++ b/common/src/main/java/com/google/auto/common/GeneratedAnnotationSpecs.java @@ -54,15 +54,6 @@ public final class GeneratedAnnotationSpecs { .map(annotation -> annotation.addMember("comments", "$S", comments).build()); } - private static Optional<AnnotationSpec.Builder> generatedAnnotationSpecBuilder( - Elements elements, Class<?> processorClass) { - return GeneratedAnnotations.generatedAnnotation(elements) - .map( - generated -> - AnnotationSpec.builder(ClassName.get(generated)) - .addMember("value", "$S", processorClass.getCanonicalName())); - } - /** * Returns {@code @Generated("processorClass"} for the target {@code SourceVersion}. * @@ -91,6 +82,15 @@ public final class GeneratedAnnotationSpecs { } private static Optional<AnnotationSpec.Builder> generatedAnnotationSpecBuilder( + Elements elements, Class<?> processorClass) { + return GeneratedAnnotations.generatedAnnotation(elements) + .map( + generated -> + AnnotationSpec.builder(ClassName.get(generated)) + .addMember("value", "$S", processorClass.getCanonicalName())); + } + + private static Optional<AnnotationSpec.Builder> generatedAnnotationSpecBuilder( Elements elements, SourceVersion sourceVersion, Class<?> processorClass) { return GeneratedAnnotations.generatedAnnotation(elements, sourceVersion) .map( diff --git a/common/src/main/java/com/google/auto/common/MoreTypes.java b/common/src/main/java/com/google/auto/common/MoreTypes.java index bd613fe4..a1a24f4a 100644 --- a/common/src/main/java/com/google/auto/common/MoreTypes.java +++ b/common/src/main/java/com/google/auto/common/MoreTypes.java @@ -866,12 +866,7 @@ public final class MoreTypes { @Override public Boolean visitDeclared(DeclaredType type, Void ignored) { - TypeElement typeElement; - try { - typeElement = MoreElements.asType(type.asElement()); - } catch (IllegalArgumentException iae) { - throw new IllegalArgumentException(type + " does not represent a class or interface."); - } + TypeElement typeElement = MoreElements.asType(type.asElement()); return typeElement.getQualifiedName().contentEquals(clazz.getCanonicalName()); } } @@ -898,7 +893,7 @@ public final class MoreTypes { @Override public boolean apply(TypeMirror input) { return input.getKind().equals(TypeKind.DECLARED) - && (MoreElements.asType(MoreTypes.asDeclared(input).asElement())) + && MoreElements.asType(MoreTypes.asDeclared(input).asElement()) .getKind() .equals(ElementKind.CLASS) && !types.isSameType(objectType, input); |