File tree Expand file tree Collapse file tree 4 files changed +42
-17
lines changed
main/java/io/avaje/inject/generator
test/java/io/avaje/inject/generator Expand file tree Collapse file tree 4 files changed +42
-17
lines changed Original file line number Diff line number Diff line change @@ -141,26 +141,26 @@ static String shortName(String fullType) {
141
141
final int p = fullType .lastIndexOf ('.' );
142
142
if (p == -1 ) {
143
143
return fullType ;
144
- } else if (fullType .startsWith ("java" )) {
145
- return fullType .substring (p + 1 );
146
- } else {
147
- var result = "" ;
148
- var foundClass = false ;
149
- for (final String part : fullType .split ("\\ ." )) {
150
- char firstChar = part .charAt (0 );
151
- if (foundClass
152
- || Character .isUpperCase (firstChar )
153
- || !Character .isAlphabetic (firstChar ) && Character .isJavaIdentifierStart (firstChar )) {
154
- foundClass = true ;
155
- result += (result .isEmpty () ? "" : "." ) + part ;
156
- }
144
+ }
145
+
146
+ String [] parts = fullType .split ("\\ ." );
147
+ StringBuilder result = new StringBuilder ();
148
+ boolean foundClass = false ;
149
+
150
+ for (String part : parts ) {
151
+ char firstChar = part .charAt (0 );
152
+ if (!foundClass && Character .isUpperCase (firstChar )) {
153
+ foundClass = true ;
157
154
}
158
- // when in doubt, do the basic thing
159
- if (result .isBlank ()) {
160
- return fullType .substring (p + 1 );
155
+ if (foundClass ) {
156
+ if (result .length () > 0 ) {
157
+ result .append ("." );
158
+ }
159
+ result .append (part );
161
160
}
162
- return result ;
163
161
}
162
+
163
+ return result .length () > 0 ? result .toString () : fullType .substring (p + 1 );
164
164
}
165
165
166
166
static String shortName (UType uType ) {
Original file line number Diff line number Diff line change @@ -144,4 +144,12 @@ void sanitizeImports() {
144
144
assertEquals ("my.Foo" , Util .sanitizeImports ("@org.bar.annotationMcgee my.Foo" ));
145
145
assertEquals ("java.util.String" , Util .sanitizeImports ("java.util.String>" ));
146
146
}
147
+
148
+ @ Test
149
+ void testShortName_nestedTypes () {
150
+ assertEquals ("Flow.Publisher" , Util .shortName ("java.util.concurrent.Flow.Publisher" ));
151
+ assertEquals ("Outer.Inner" , Util .shortName ("com.foo.Outer.Inner" ));
152
+ assertEquals ("Only" , Util .shortName ("a.b.c.Only" ));
153
+ assertEquals ("simple" , Util .shortName ("simple" ));
154
+ }
147
155
}
Original file line number Diff line number Diff line change
1
+ package io .avaje .inject .generator .models .valid .generic ;
2
+
3
+ import jakarta .inject .Singleton ;
4
+ import java .util .concurrent .Flow ;
5
+ import java .util .concurrent .SubmissionPublisher ;
6
+
7
+ @ Singleton
8
+ public class GenericImpl implements GenericInterfaceObject <Flow .Publisher <Object >> {
9
+ public Flow .Publisher <Object > get () {
10
+ return new SubmissionPublisher ();
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ package io .avaje .inject .generator .models .valid .generic ;
2
+
3
+ public interface GenericInterfaceObject <T > {
4
+ T get ();
5
+ }
You can’t perform that action at this time.
0 commit comments