sdedic commented on code in PR #7068:
URL: https://github.com/apache/netbeans/pull/7068#discussion_r1490866411


##########
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/Utils.java:
##########
@@ -200,46 +190,53 @@ public static List<VariableElement> 
getRepositoriesFor(CompilationInfo info, Typ
         return repositories;
     }
 
-    public static MethodTree createControllerDataEndpointMethod(WorkingCopy 
copy, TypeElement repositoryTypeElement, String repositoryFieldName, String 
delegateMethodName, String idProefix) {
+    public static MethodTree 
createControllerFindAllDataEndpointMethod(WorkingCopy copy, TypeElement 
repositoryTypeElement, String repositoryFieldName, String controllerId, String 
idProefix) {
         TypeMirror repositoryType = repositoryTypeElement.asType();
         if (repositoryType.getKind() == TypeKind.DECLARED) {
-            List<ExecutableElement> repositoryMethods = 
ElementFilter.methodsIn(copy.getElements().getAllMembers(repositoryTypeElement));
-            ExecutableElement delegateMethod = null;
-            if ("findAll".equals(delegateMethodName)) { //NOI18N
-                for (ExecutableElement method : 
repositoryMethods.stream().filter(el -> 
delegateMethodName.contentEquals(el.getSimpleName())).collect(Collectors.toList()))
 {
-                    List<? extends VariableElement> params = 
method.getParameters();
-                    if (delegateMethod == null && params.isEmpty()) {
-                        delegateMethod = method;
-                    } else if (params.size() == 1) {
-                        TypeMirror paramType = params.get(0).asType();
-                        if (paramType.getKind() == TypeKind.DECLARED && 
"io.micronaut.data.model.Pageable".contentEquals(((TypeElement) ((DeclaredType) 
paramType).asElement()).getQualifiedName())) { //NOI18N
-                            delegateMethod = method;
-                        }
-                    }
+            TypeMirror pageableRepositoryType = 
copy.getTypes().erasure(copy.getElements().getTypeElement(PAGEABLE_REPOSITORY_TYPE_NAME).asType());
+            boolean isPageableRepository = 
copy.getTypes().isSubtype(copy.getTypes().erasure(repositoryType), 
pageableRepositoryType);
+            ExecutableElement delegateMethod = 
ElementFilter.methodsIn(copy.getElements().getAllMembers(repositoryTypeElement)).stream().filter(method
 -> {
+                if (!"findAll".contentEquals(method.getSimpleName())) { 
//NOI18N
+                    return false;
                 }
-            } else {
-                delegateMethod = repositoryMethods.stream().filter(method -> 
delegateMethodName.contentEquals(method.getSimpleName()) && 
method.getParameters().size() == 1).findAny().orElse(null);
-            }
+                if (isPageableRepository) {
+                    TypeMirror paramType = method.getParameters().size() == 1 
? method.getParameters().get(0).asType() : null;
+                    return paramType != null && paramType.getKind() == 
TypeKind.DECLARED && PAGEABLE_TYPE_NAME.contentEquals(((TypeElement) 
((DeclaredType) paramType).asElement()).getQualifiedName());
+                }
+                return method.getParameters().isEmpty();
+            }).findFirst().get();

Review Comment:
   `orElse(null)` should work better  with `delegateMethod != null` test.



##########
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:
##########
@@ -94,8 +104,13 @@ public class MicronautDataEndpointGenerator implements 
CodeActionProvider, Comma
     private static final String OFFSET =  "offset";
     private static final String REPOSITORIES =  "repositories";
     private static final String ENDPOINTS =  "endpoints";
+    private static final String CONTROLLER_ID =  "controllerId";
 
-    private final Gson gson = new Gson();
+    private final Gson gson = new 
GsonBuilder().registerTypeAdapter(NotifyDescriptor.QuickPick.Item.class, 
(JsonDeserializer<NotifyDescriptor.QuickPick.Item>) (JsonElement json, Type 
type, JsonDeserializationContext jdc) -> {

Review Comment:
   Maybe this could be promoted to LSP server implementation, into the 
'standard' Gson setup ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to