You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "dbalek (via GitHub)" <gi...@apache.org> on 2024/02/14 09:47:09 UTC

[PR] Micronaut PUT/POST Data Endpoint Method generation added. [netbeans]

dbalek opened a new pull request, #7068:
URL: https://github.com/apache/netbeans/pull/7068

   Adding an ability to generate PUT and POST Data Endpoint methods inside Micronaut Controller classes via code completion and source action (in addition to the already covered GET and DELETE introduced in https://github.com/apache/netbeans/pull/6799


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


Re: [PR] Micronaut PUT/POST Data Endpoint Method generation added. [netbeans]

Posted by "dbalek (via GitHub)" <gi...@apache.org>.
dbalek commented on code in PR #7068:
URL: https://github.com/apache/netbeans/pull/7068#discussion_r1491358424


##########
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:
   Could be done later if more than the single use-case appears.



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


Re: [PR] Micronaut PUT/POST Data Endpoint Method generation added. [netbeans]

Posted by "dbalek (via GitHub)" <gi...@apache.org>.
dbalek merged PR #7068:
URL: https://github.com/apache/netbeans/pull/7068


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


Re: [PR] Micronaut PUT/POST Data Endpoint Method generation added. [netbeans]

Posted by "sdedic (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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