1414
1515package com .google .devtools .build .runfiles ;
1616
17- import static java .util .stream .Collectors .joining ;
18- import static java .util .stream .Collectors .toList ;
1917
2018import java .io .IOException ;
2119import java .io .PrintWriter ;
22- import java .util .Collections ;
23- import java .util .List ;
20+ import java .util .ArrayDeque ;
21+ import java .util .Deque ;
2422import java .util .Set ;
25- import java .util .stream .Stream ;
2623import javax .annotation .processing .AbstractProcessor ;
2724import javax .annotation .processing .RoundEnvironment ;
2825import javax .annotation .processing .SupportedAnnotationTypes ;
2926import javax .annotation .processing .SupportedOptions ;
3027import javax .lang .model .SourceVersion ;
3128import javax .lang .model .element .Element ;
32- import javax .lang .model .element .Name ;
3329import javax .lang .model .element .TypeElement ;
3430import javax .tools .Diagnostic .Kind ;
3531
@@ -51,7 +47,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
5147 .flatMap (element -> roundEnv .getElementsAnnotatedWith (element ).stream ())
5248 .map (element -> (TypeElement ) element )
5349 .forEach (this ::emitClass );
54- return true ;
50+ return false ;
5551 }
5652
5753 private void emitClass (TypeElement annotatedClass ) {
@@ -80,18 +76,14 @@ private void emitClass(TypeElement annotatedClass) {
8076 // AutoBazelRepository_Outer_Middle_Inner.
8177 // Note: There can be collisions when local classes are involved, but since the definition of a
8278 // class depends only on the containing Bazel target, this does not result in ambiguity.
83- List <String > nestedClassNames =
84- Stream .iterate (
85- annotatedClass ,
86- element -> element instanceof TypeElement ,
87- Element ::getEnclosingElement )
88- .map (Element ::getSimpleName )
89- .map (Name ::toString )
90- .collect (toList ());
91- Collections .reverse (nestedClassNames );
92- String generatedClassSimpleName =
93- Stream .concat (Stream .of ("AutoBazelRepository" ), nestedClassNames .stream ())
94- .collect (joining ("_" ));
79+ Deque <String > classNameSegments = new ArrayDeque <>();
80+ Element element = annotatedClass ;
81+ while (element instanceof TypeElement ) {
82+ classNameSegments .addFirst (element .getSimpleName ().toString ());
83+ element = element .getEnclosingElement ();
84+ }
85+ classNameSegments .addFirst ("AutoBazelRepository" );
86+ String generatedClassSimpleName = String .join ("_" , classNameSegments );
9587
9688 String generatedClassPackage =
9789 processingEnv .getElementUtils ().getPackageOf (annotatedClass ).getQualifiedName ().toString ();
0 commit comments