fernando88to commented on code in PR #17:
URL: 
https://github.com/apache/grails-intellij-plugin/pull/17#discussion_r3775162293


##########
plugin/src/test/java/org/apache/grails/intellij/plugin/domain/GrailsBuildableCriteriaTest.java:
##########
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.grails.intellij.plugin.domain;
+
+import com.intellij.codeInsight.completion.CompletionType;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiReference;
+import com.intellij.testFramework.UsefulTestCase;
+import org.apache.grails.intellij.lib.testFramework.GrailsTestCase;
+import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
+import 
org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Since GORM 4, {@code createCriteria()} returns {@code BuildableCriteria} 
instead of
+ * {@code HibernateCriteriaBuilder}, so out of the box only the 
closure-terminal calls that interface
+ * declares itself ({@code get}, {@code list}, ...) resolve. The GORM 
libraries the other tests run against
+ * are older than that, hence the stubs below for the pieces of a GORM 5 
classpath the plugin looks at.
+ */
+public class GrailsBuildableCriteriaTest extends GrailsTestCase {
+  /**
+   * The bundled GORM is older than 4, and so is its {@code 
grails.orm.HibernateCriteriaBuilder}: it does not
+   * implement {@code BuildableCriteria}. That hierarchy is what 
CriteriaBuilderUtil.isCriteriaBuilderMethod()
+   * keys off, so the builder is stubbed below instead of taken from the 
library.
+   */
+  @Override
+  protected boolean needGormLibrary() {
+    return false;
+  }
+
+  /** GormTraitContributor only picks GormEntity when {@code 
org.hibernate.Hibernate} is on the classpath. */
+  @Override
+  protected boolean needHibernate() {
+    return true;
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+
+    
myFixture.addFileToProject("src/java/org/grails/datastore/mapping/query/api/Criteria.java",
 """
+      package org.grails.datastore.mapping.query.api;
+
+      import groovy.lang.Closure;
+
+      public interface Criteria {
+        Criteria eq(String propertyName, Object value);
+        Criteria ge(String propertyName, Object value);
+        Criteria order(String propertyName, String direction);
+        Criteria and(Closure callable);
+      }
+      """);
+
+    
myFixture.addFileToProject("src/java/org/grails/datastore/mapping/query/api/BuildableCriteria.java",
 """
+      package org.grails.datastore.mapping.query.api;
+
+      import groovy.lang.Closure;
+
+      public interface BuildableCriteria extends Criteria {
+        Object get(Closure callable);
+        Object list(Closure callable);
+        Object listDistinct(Closure callable);
+        Object scroll(Closure callable);

Review Comment:
    Both closed in ebd3f85, and I checked the stub against the real interface 
source rather than from memory — `BuildableCriteria.java` on 
`apache/grails-data-mapping` master confirms all four things at
     once: every terminal returns `Object`, every closure param carries 
`@DelegatesTo(Criteria.class)`, `list(Map, Closure)` is there, and there's no 
`count` — which is the premise of this whole fix, now
     verified at the source.
   
     So: added `list(Map, Closure)` and the `@DelegatesTo` annotations, with a 
comment saying the annotations are fixture rather than decoration, since the 
competing `Criteria` delegate is the thing the
     stub wasn't modelling. Left out 
`getTargetClass`/`cache`/`readOnly`/`join`/`select` with a note — nothing in 
the plugin looks at them, and `join(String, JoinType)` would drag in 
`javax.persistence`.
   
     One side effect worth flagging: adding the overload broke 
`testCompletionListsEveryMemberOnce`, because `list` now shows up twice in 
completion. Those are the two real overloads, not a contributed
     member duplicating a declared one — so the test now asserts `count` and 
`get` at 1 and `list` at 2, with a comment on the distinction. The 
`@DelegatesTo` annotations on their own changed no inferred
     type.
   
     Agreed on the `#CHECK#` convention carrying a lot of weight here — that's 
why I put the marker on the stub itself.
   



-- 
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]

Reply via email to