boolean (GrReferenceExpression refExpr) { final GrExpression qualifier = refExpr.getQualifierExpression(); if (qualifier == null) { final PsiClass clazz = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); if (clazz == null) { //script return true; } return false; //in class, a property should normally be defined, so it's not a declaration } final PsiType type = qualifier.getType(); if (type instanceof PsiClassType classType && !(qualifier instanceof GrReferenceExpression && ((GrReferenceExpression)qualifier).resolve() instanceof GroovyScriptClass)) { final PsiClass psiClass = classType.resolve(); if (psiClass instanceof GroovyScriptClass) { return true; } } return false; }