Skip to content

Commit

Permalink
Only generate scope constants for custom scopes. (#9504)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer authored Nov 15, 2024
1 parent 86122fc commit ba8bdd1
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2270,17 +2270,31 @@ private void qualifiersMethod(ClassModel.Builder classModel, DescribedService se

private void scopeMethod(ClassModel.Builder classModel, DescribedService service) {
// TypeName scope()
classModel.addField(scopesField -> scopesField
.isStatic(true)
.isFinal(true)
.name("SCOPE")
.type(TypeNames.TYPE_NAME)
.addContentCreate(service.scope()));
TypeName scope = service.scope();

classModel.addMethod(scopeMethod -> scopeMethod.name("scope")
.addAnnotation(Annotations.OVERRIDE)
.returnType(TypeNames.TYPE_NAME)
.addContentLine("return SCOPE;"));
if (scope.packageName().equals(INJECTION_SINGLETON.packageName())
&& scope.enclosingNames().size() == 1 && scope.enclosingNames().getFirst().equals("Injection")) {
// only method
classModel.addMethod(scopeMethod -> scopeMethod.name("scope")
.addAnnotation(Annotations.OVERRIDE)
.returnType(TypeNames.TYPE_NAME)
.addContent("return ")
.addContent(scope)
.addContentLine(".TYPE;"));
} else {
// field and method
classModel.addField(scopesField -> scopesField
.isStatic(true)
.isFinal(true)
.name("SCOPE")
.type(TypeNames.TYPE_NAME)
.addContentCreate(scope));

classModel.addMethod(scopeMethod -> scopeMethod.name("scope")
.addAnnotation(Annotations.OVERRIDE)
.returnType(TypeNames.TYPE_NAME)
.addContentLine("return SCOPE;"));
}
}

private void weightMethod(ClassModel.Builder classModel, DescribedService service) {
Expand Down

0 comments on commit ba8bdd1

Please sign in to comment.