fernando88to commented on code in PR #17: URL: https://github.com/apache/grails-intellij-plugin/pull/17#discussion_r3775146236
########## plugin/src/main/java/org/apache/grails/intellij/plugin/references/domain/criteria/BuildableCriteriaImplicitMemberContributor.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.references.domain.criteria; + +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiType; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.DelegatingScopeProcessor; +import com.intellij.psi.scope.PsiScopeProcessor; +import com.intellij.psi.util.InheritanceUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; +import org.jetbrains.plugins.groovy.util.dynamicMembers.DynamicMemberUtils; + +import java.util.Set; + +/** + * Since GORM 4 {@code createCriteria()} comes from the {@code GormEntity} trait and is declared to return + * {@link #BUILDABLE_CRITERIA_CLASS}, not {@link CriteriaBuilderUtil#CRITERIA_BUILDER_CLASS}. That interface + * declares {@code get}, {@code list}, {@code listDistinct} and {@code scroll}, which is why those forms + * resolve out of the box, but the remaining closure-terminal calls only exist in + * {@code AbstractHibernateCriteriaBuilder.invokeMethod(...)} and are therefore invisible to resolution: + * {@code Ddd.createCriteria().count { ... }} used to resolve to nothing, which in turn left + * {@link CriteriaBuilderUtil#checkCriteriaClosure} unable to find the domain class, so no property inside + * the closure could be navigated either. + */ +final class BuildableCriteriaImplicitMemberContributor extends NonCodeMembersContributor { + public static final String BUILDABLE_CRITERIA_CLASS = "org.grails.datastore.mapping.query.api.BuildableCriteria"; + + /** + * Members of {@link CriteriaBuilderImplicitMemberContributor#CLASS_SOURCE} that + * {@link #BUILDABLE_CRITERIA_CLASS} (or its {@code Criteria} supertype) does not declare itself. + * Contributing the rest would duplicate real methods. + */ + // #CHECK# org.grails.datastore.mapping.query.api.BuildableCriteria against org.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder#invokeMethod(...) + private static final Set<String> MEMBERS_MISSING_FROM_BUILDABLE_CRITERIA = Set.of("count", "call", "doCall"); Review Comment: Reworded in 39697b7. The set is now described as the missing **qualifier-level terminal** calls, and the javadoc says outright why `projections` is excluded — closure-body member, supplied inside the closure by `CriteriaClosureMemberContributor`, and adding it here would put a bogus entry on every `createCriteria()` qualifier. That was the trap worth closing: by the old wording the next person auditing the `#CHECK#` would have "fixed" it. On `doCall`: you're right, and the claim actually lived in the `testShorthandCallForm` javadoc, so I fixed it there too. Only `call` backs the shorthand — that's what Groovy's implicit-call resolution looks for. `doCall` is closure protocol, kept for `CLASS_SOURCE` parity, and the javadoc now says exactly that instead of crediting it. -- 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]
