Skip to content

Commit

Permalink
Prefer javax.annotation.processing.Generated on Java 9
Browse files Browse the repository at this point in the history
Closes google#560.
  • Loading branch information
davido committed Dec 8, 2017
1 parent c9fd48f commit 2b720d0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static java.util.stream.Collectors.toCollection;

import com.google.auto.common.GeneratedAnnotations;
import com.google.auto.common.MoreElements;
import com.google.auto.common.SuperficialValidation;
import com.google.auto.service.AutoService;
Expand All @@ -35,7 +36,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Generated;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
Expand Down Expand Up @@ -191,12 +191,12 @@ private void processMethod(ExecutableElement method) {
}

private String getGeneratedTypeName(TypeSimplifier typeSimplifier) {
TypeElement generatedTypeElement =
processingEnv.getElementUtils().getTypeElement("javax.annotation.Generated");
if (generatedTypeElement == null) {
Optional<TypeElement> generatedTypeElement =
GeneratedAnnotations.generatedAnnotation(processingEnv.getElementUtils());
if (!generatedTypeElement.isPresent()) {
return "";
}
return typeSimplifier.simplify(generatedTypeElement.asType());
return typeSimplifier.simplify(generatedTypeElement.get().asType());
}

/**
Expand Down Expand Up @@ -447,7 +447,8 @@ private Set<TypeMirror> getReferencedTypes(
Set<Class<?>> wrapperTypesUsedInCollections) {
Set<TypeMirror> types = new TypeMirrorSet();
types.add(annotation);
types.add(getTypeMirror(Generated.class));
types.add(
GeneratedAnnotations.generatedAnnotation(processingEnv.getElementUtils()).get().asType());
for (VariableElement parameter : method.getParameters()) {
// Method parameter types are usually the same as annotation member types, but in the case of
// List<Integer> for int[] we are referencing List.
Expand Down

0 comments on commit 2b720d0

Please sign in to comment.